Skip to content

Instantly share code, notes, and snippets.

@pjcodesjs
Created March 12, 2023 04:37
Show Gist options
  • Save pjcodesjs/12b35be82344e49afaa6febfccf7cd43 to your computer and use it in GitHub Desktop.
Save pjcodesjs/12b35be82344e49afaa6febfccf7cd43 to your computer and use it in GitHub Desktop.
function isPalindrome(head) {
let arr = [];
let current = head;
while (current) {
arr.push(current.val);
current = current.next;
}
let i = 0;
let j = arr.length - 1;
while (i < j) {
if (arr[i] !== arr[j]) {
return false;
}
i++;
j--;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment