We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2befeb3 commit 40b3d07Copy full SHA for 40b3d07
C++/swap-nodes-in-pairs.cpp
@@ -12,17 +12,17 @@
12
class Solution {
13
public:
14
ListNode* swapPairs(ListNode* head) {
15
- ListNode dummy = ListNode(0);
+ ListNode dummy{0};
16
dummy.next = head;
17
- ListNode *cur = &dummy;
18
- while (cur->next && cur->next->next) {
19
- ListNode *next_one = cur->next;
20
- ListNode *next_two = next_one->next;
21
- ListNode *next_three = next_two->next;
22
- cur->next = next_two;
+ auto curr = &dummy;
+ while (curr->next && curr->next->next) {
+ auto next_one = curr->next;
+ auto next_two = next_one->next;
+ auto next_three = next_two->next;
+ curr->next = next_two;
23
next_two->next = next_one;
24
next_one->next = next_three;
25
- cur = next_one;
+ curr = next_one;
26
}
27
return dummy.next;
28
0 commit comments