Skip to content

Commit 3cc2899

Browse files
authored
Update 2074.Reverse-Nodes-in-Even-Length-Groups.cpp
1 parent 5ed6304 commit 3cc2899

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Linked_List/2074.Reverse-Nodes-in-Even-Length-Groups/2074.Reverse-Nodes-in-Even-Length-Groups.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ class Solution {
5757

5858
ListNode* reverseLinkedList(ListNode* head)
5959
{
60-
ListNode* h = head;
60+
ListNode* cur = head;
6161
ListNode* last = NULL;
62-
while (h!=NULL)
62+
ListNode* next = NULL;
63+
while (cur!=NULL)
6364
{
64-
ListNode* nxt = h->next;
65-
h->next = last;
66-
last = h;
67-
h = nxt;
65+
next = cur->next;
66+
cur->next = last;
67+
last = cur;
68+
cur = next;
6869
}
6970
return last;
7071
}

0 commit comments

Comments
 (0)