zoukankan      html  css  js  c++  java
  • 判断链表的回文结构

    
    #define Node ListNode
    
    class Solution {
    public:
        /**
         * 
         * @param head ListNode类 the head
         * @return bool布尔型
         */
        bool isPail(ListNode* head) {
            if(head==NULL ||head->next ==NULL) return true;
            // write code here
            ListNode*first=head,*last=head;
            while(first && first->next) first=first->next->next,last=last->next;
            stack<Node*>s;
            while(last) {
                s.push(last);
                last = last->next;
            }
            last = head;
            while(s.size() && last->val == s.top()->val) last = last->next,s.pop();
            return s.empty();
            
        }
    };
    
    
  • 相关阅读:
    10.28作业
    10.27作业
    10.26作业
    10.22作业
    10.20作业
    10.19作业
    10.16作业
    10.15作业
    10.14作业
    10.13作业
  • 原文地址:https://www.cnblogs.com/lyr-2000/p/14322388.html
Copyright © 2011-2022 走看看