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 temp=judge(head->next);
    if(!temp) return false;
    if(head->val!=pre->val) return false;
    pre=pre->next;
    return true;
}

bool isPalindrome(struct ListNode* head) {
    pre=head;
    return judge(head);    
}

 

posted on 2024-03-15 21:42  神奇的萝卜丝  阅读(12)  评论(0)    收藏  举报