Skip to content

Commit b912c14

Browse files
Create Palindromic LinkedList-234
1 parent ee3d2dd commit b912c14

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Palindromic LinkedList-234

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public boolean isPalindrome(ListNode head) {
3+
Stack<Integer> stk = new Stack<>();
4+
ListNode curr = head;
5+
boolean ans = true;
6+
while(curr!=null){
7+
stk.push(curr.val);
8+
curr = curr.next;
9+
}
10+
while(head!=null){
11+
int cur = stk.pop();
12+
if(head.val==cur){
13+
ans = true;
14+
}else{
15+
ans= false;
16+
break;
17+
}
18+
head = head.next;
19+
}
20+
return ans;
21+
}
22+
}

0 commit comments

Comments
 (0)