Palindrome List Time : Space : 12345678910111213141516171819202122232425262728293031323334353637383940414243/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ListNode* find(ListNode* A) { ListNode* slow = A; ListNode* fast = A; while(fast->next and fast->next->next) { fast = fast->next->next; slow = slow->next; } return slow; } ListNode* reverse(ListNode* A) { ListNode* dummy = new ListNode(-1); ListNode* runner = A; while(runner) { ListNode* next = runner->next; runner->next = dummy->next; dummy->next = runner; runner = next; } return dummy->next; }int Solution::lPalin(ListNode* A) { if(A->next == NULL) return true; ListNode* mid = find(A); ListNode* cut = mid->next; mid->next = NULL; ListNode* rev = reverse(cut); ListNode* runner = A; while(rev) { if(rev->val != runner->val) return false; rev = rev->next; runner = runner->next; } return true;}