题解 | 链表的回文结构
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ #include <csetjmp> class PalindromeList { public: bool chkPalindrome(ListNode* A) { struct ListNode* ptr=A; int k=0,i=0,j=0; while(ptr) { k++; ptr=ptr->next; } int a=k/2; int b=k%2; while(A) { if(a>0 && b==0) { i+=A->val; } if(a<=0 && b==0) { j+=A->val; } if(a>0 && b==1) { i+=A->val; } if(a<0 && b==1) { j+=A->val; } a--; A=A->next; } return i==j?true:false; } };