Skip to content

Instantly share code, notes, and snippets.

@berkayk
Created January 29, 2016 16:41
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 berkayk/81fdad62a2306f247d4d to your computer and use it in GitHub Desktop.
Save berkayk/81fdad62a2306f247d4d to your computer and use it in GitHub Desktop.
class Node {
Node next;
Node prev;
int data;
public Node(int value) {
this.data = value;
}
}
public boolean isPalindrome(Node head) {
if (head == null)
return false;
Node tail;
Node node = head;
while (node != null) {
Node prev = node;
node = node.next;
if (node != null) {
node.prev = prev;
}
else {
tail = prev;
}
}
while (head != tail && tail.next != head) {
if (head.data == tail.data) {
head = head.next;
tail = tail.prev;
}
else
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment