[leetcode] 234. Palindrome Linked List (easy)

原题
回文 水题

function ListNode(val) {
  this.val = val;
  this.next = null;
}
/**
 * @param {ListNode} head
 * @return {boolean}
 */
var isPalindrome = function(head) {
  var list = [];
  while (head) {
    list.push(head.val);
    head = head.next;
  }
  for (let i = 0; i < (list.length + 1) / 2; i++) {
    if (list[i] !== list[list.length - i - 1]) {
      return false;
    }
  }
  return true;
};
posted @ 2018-10-09 00:04  Ruohua3kou  阅读(92)  评论(0编辑  收藏  举报