234回文链表

// 其一,find mid node 使用快慢指针找到链表中点。 
// 其二,reverse 逆序后半部分。 
// 其三,check 从头、中点,开始比较是否相同。
var isPalindrome = function(head) {
  let slow = head
  let fast = head
  let pre = null
  while(fast) {
      console.log('fast:', fast)
      slow = slow.next
      fast = fast.next ? fast.next.next : fast.next
  }
  // 反转
  while(slow) {
      console.log('slow',slow)
      let next = slow.next
      slow.next = pre
      pre = slow
      slow = next
  }
  // 检查
  while(head && pre) {
      console.log('head',head)
      console.log('pre', pre)
      if(head.val !== pre.val) return false
      head = head.next
      pre = pre.next
  }
  return true
};
原文地址:https://www.cnblogs.com/lyt0207/p/14001473.html