Skip to content

Commit 3282743

Browse files
committed
Update remove-duplicates-from-sorted-list-ii.cpp
1 parent d52ac1d commit 3282743

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

C++/remove-duplicates-from-sorted-list-ii.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
class Solution {
1313
public:
1414
ListNode* deleteDuplicates(ListNode* head) {
15-
ListNode dummy = ListNode(0);
16-
ListNode *pre = &dummy;
15+
ListNode dummy{0};
16+
auto prev = &dummy;
1717
while (head) {
1818
if (head->next && head->next->val == head->val) {
1919
auto val = head->val;
2020
while (head && head->val == val) {
2121
head = head->next;
2222
}
23-
pre->next = head;
23+
prev->next = head;
2424
} else {
25-
pre->next = head;
26-
pre = head;
25+
prev->next = head;
26+
prev = head;
2727
head = head->next;
2828
}
2929
}

0 commit comments

Comments
 (0)