leetcode - 234. Palindrome Linked List

摸不着头脑
在这里插入图片描述

class Solution {
public:
    bool isPalindrome(ListNode* head) {
        vector<int>a;
        while(head)
        {
            a.push_back(head->val);
            head=head->next;
        }
        int e=a.size()-1,b(0);
        while(b<e)
        {
            if(a[e]!=a[b])
            {
                return 0;
            }
            ++b;
            --e;
        }
        return 1;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_41938758/article/details/88954548