boolisPalindrome(ListNode* head){ ListNode* left = head, *slow = head, *fast = head; while (fast != nullptr && fast->next != nullptr) { slow = slow->next; fast = fast->next->next; } if (fast) { slow = slow->next; } ListNode* right = reverse(slow); // running the while loop against right since the end of right // is nullptr while left would still have items to iterate on while (right) { if (left->val != right->val) { returnfalse; } else { right = right->next; left = left->next; } } returntrue; }