Skip to content

Commit 7cb679c

Browse files
authored
Merge pull request #2229 from Ykhan799/main
Create: 0083-remove-duplicates-from-sorted-list.c
2 parents 6dfd3bc + 6176c62 commit 7cb679c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: c/0083-remove-duplicates-from-sorted-list.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* struct ListNode *next;
6+
* };
7+
*/
8+
9+
// Time: O(n)
10+
// Space: O(1)
11+
struct ListNode* deleteDuplicates(struct ListNode* head){
12+
struct ListNode* cur = head;
13+
while (cur) {
14+
while (cur->next && cur->next->val == cur->val) {
15+
cur->next = cur->next->next;
16+
}
17+
cur = cur->next;
18+
}
19+
return head;
20+
}

0 commit comments

Comments
 (0)