1. 程式人生 > >LeetCode 234 Palindrome Linked List(回文鏈表)(*)(?)

LeetCode 234 Palindrome Linked List(回文鏈表)(*)(?)

給定 回文 val ren ace 一個 markdown track per

翻譯

給定一個單鏈表,確定它是否是回文的。

跟進: 你能夠在O(n)時間和O(1)空間下完畢它嗎?

原文

Given a singly linked list, determine if it is a palindrome.

Follow up:
Could you do it in O(n) time and O(1) space?

進階

bool judge(ListNode *head, ListNode* &cur) {
    if (!head)
        return true;
    if (!judge(head->
next, cur)) return false; if (cur->val != head->val) return false; else { cur = cur->next; return true; } } bool isPalindrome(ListNode* head) { ListNode *cur = head; return judge(head, cur); }
‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); });

    LeetCode 234 Palindrome Linked List(回文鏈表)(*)(?)