判断是否为回文链表
/** * 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 };
以自己现在的努力程度,还没有资格和别人拼天赋