美文网首页
[LeetCode] 234. Palindrome Linke

[LeetCode] 234. Palindrome Linke

作者: 弱花 | 来源:发表于2018-11-02 11:38 被阅读0次

原题

回文 水题

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;
};

相关文章

网友评论

      本文标题:[LeetCode] 234. Palindrome Linke

      本文链接:https://www.haomeiwen.com/subject/xyiqxqtx.html