Palindrome linked list
Easylinked listtwo pointersfast and slow pointers
Return true if the list's values read the same forwards and backwards. Try O(1) extra memory.
Example 1
Input: head = [1,2,2,1] Output: true
Example 2
Input: head = [1,2] Output: false
Constraints
- 1 ≤ number of nodes ≤ 10⁵
- 0 ≤ Node.val ≤ 9
Submit checks your solution against 11 tests, including hidden ones.
// Provided by the judge: keep these definitions
class ListNode {
constructor(val = 0, next = null) {
this.val = val
this.next = next
}
}
/**
* @param {ListNode|null} head
* @return {bool}
*/
function isPalindrome(head) {
}