首页 > 其他 > 详细

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

时间:2017-07-03 20:33:02      阅读:307      评论:0      收藏:0      [点我收藏+]

翻译

给定一个单链表,确定它是否是回文的。

跟进: 你能够在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);
}

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

原文:http://www.cnblogs.com/yangykaifa/p/7112722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!