Created
July 2, 2014 04:12
-
-
Save iwilbert/cdb703fcb9b665551ae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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