llllmz

导航

234. 回文链表c

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* pre;

bool judge(struct ListNode* head){
    if(!head) return true;
    bool a=judge(head->next);
    if( !a || pre->val!=head->val) return false;
    pre=pre->next;
    return true;
}

bool isPalindrome(struct ListNode* head) {
    if(!head->next) return true;
    pre=head;
    return judge(head);
} 

 

posted on 2024-03-21 20:27  神奇的萝卜丝  阅读(2)  评论(0编辑  收藏  举报