Skip to content

Instantly share code, notes, and snippets.

@iwilbert
Created July 2, 2014 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwilbert/cdb703fcb9b665551ae6 to your computer and use it in GitHub Desktop.
Save iwilbert/cdb703fcb9b665551ae6 to your computer and use it in GitHub Desktop.
public boolean isPalindrome(ListNode head) {
if(head == null)
return true;
Stack<Integer> S = new Stack<Integer>();
ListNode cur = head;
while(cur != null) {
S.push(cur.val);
cur = cur.next;
}
cur = head;
while(cur != null) {
if(S.pop() != cur.val)
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment