Created
March 12, 2023 04:37
-
-
Save pjcodesjs/12b35be82344e49afaa6febfccf7cd43 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
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