# My 17ms C++ solution, easy to understand, with comments

• Basic idea is to find the middle point of the linked list, then reverse the 2nd half.
Notice that since reversed linked list is just half as long as the original one, one just need to compare half of the original linked list with the reversed one.

``````class Solution {
private:
// Special case
}
// Normal case
else {
ListNode* prev = nullptr;
while (curr != nullptr) {
ListNode* nex = curr->next;
curr->next = prev;
prev = curr;
curr = nex;
}
return prev;
}
}

// Special cases
return true;
}
else {
return false;
}
}
return false;
}
// Normal case
else {
}
return false;
}
else {
return true;
}
}
}

public:
// Special case
return true;
}
}
// Normal case
else {
// Step 1: determine the center of linked-list
// define 2 pointers with different moving speed
// In case of 1->2->3->2->1, slow points to 3, fast points to 1
// In case of 1->2->3->3->2->1, slow points to 2nd 3, fast points to NULL
while ( (fast != nullptr) && (fast->next != nullptr) ) {
slow = slow->next;
fast = fast->next->next;
}

// Step 2: reverse the 2nd half of the linked-list
// Case 2.1: 1->2->3->2->1, slow (pointing to 3)'s next is reversed
if ( (fast != nullptr) && (fast->next == nullptr) ) {
ListNode* reversed = reverseLinkedList(slow->next); // 1->2->NULL
// now compare each node
}
// Case 2.2: 1->2->3->3->2->1, slow (pointing to 2nd 3) is reversed
else {
ListNode* reversed = reverseLinkedList(slow);  // 1->2->3->NULL
// now compare each node