diff --git a/OJ notes/pages/Leetcode Reverse-Linked-List.md b/OJ notes/pages/Leetcode Reverse-Linked-List.md index c30f5a1..f361703 100644 --- a/OJ notes/pages/Leetcode Reverse-Linked-List.md +++ b/OJ notes/pages/Leetcode Reverse-Linked-List.md @@ -102,7 +102,12 @@ The iteration method use two pointers: - one that points to the new head, as an anchor - The other one points to nodes we need to iterate over: +The iterator **has** to be pointing to head, and use +`cur->next` instead of directly using cur, otherwise will +lead to strange loops or bugs. +The pointer moves by `cur->next = cur->next->next`, it +represents the head element. ### Solution @@ -123,6 +128,7 @@ public: // Move cur->next after pre. pre->next = cur->next; // Fix pointers, because cur->next is unchanged when changing position. + // This part is important, must use cur->next. cur->next = cur->next->next; pre->next->next = temp; }