题解 | #链表的回文结构#
链表的回文结构
https://www.nowcoder.com/practice/d281619e4b3e4a60a2cc66ea32855bfa
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ class PalindromeList { public: bool chkPalindrome(ListNode* A) { // write code here stack<ListNode> st; ListNode * p = A; while(p) { st.push(*p); p=p->next; } p = A; while(p) { ListNode N = st.top(); if(p->val==N.val) { st.pop(); p = p->next; } else { return false; } } return true; } };