/** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } */ /** * @param {ListNode} head * @return {boolean} */ const isPalindrome = (head) => { if(!head) return true const arr = [] while(head){ arr.push(head.val) head = head.next } let startIdx = 0, endIdx = arr.length - 1; while(startIdx <= endIdx){ if(arr[startIdx] !== arr[endIdx]){ return false } startIdx++ endIdx-- } return true };
标签:head,判断,return,val,arr,next,链表,回文 From: https://www.cnblogs.com/zhenjianyu/p/17083658.html