IsListPalindrome
Idea
Code
boolean solution(ListNode<Integer> head) {
ListNode<Integer> slow = head;
boolean ispalin = true;
Stack<Integer> stack = new Stack<Integer>();
while (slow != null) {
stack.push(slow.value);
slow = slow.next;
}
while (head != null) {
int i = stack.pop();
if (head.value == i) {
ispalin = true;
}
else {
ispalin = false;
break;
}
head = head.next;
}
return ispalin;
}Last updated