题解 | #判断一个链表是否为回文结构#(栈)
判断一个链表是否为回文结构
http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
class Solution { public: bool isPail(ListNode* head) { if(!head) return true; stack<ListNode *> st; int size = 0; ListNode *p = head; while(p) p = p->next,size++; p = head; int i; for(i = 0; i < size/2; i++){ st.push(p); p = p->next; } if(size%2) p = p->next; while(!st.empty()){ if(p->val != st.top()->val) return false; st.pop(); p = p->next; } return true; } };