/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:
bool chkPalindrome(ListNode* A) {
struct ListNode* slow=A;
struct ListNode* fast=A;
stack<int> s;
while(fast && fast->next)
{
s.push(slow->val);
slow=slow->next;
fast=fast->next->next;
}
if(fast)//偶数不为空
slow=slow->next;
while(slow)
{
if(s.top()!=slow->val)
{
return false;
}
s.pop();
slow=slow->next;
}
return true;
}
};



京公网安备 11010502036488号