We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 12e9707 commit f7a4c4aCopy full SHA for f7a4c4a
RemoveDuplicatesfromSortedList/RemoveDuplicatesfromSortedList.cpp
@@ -0,0 +1,36 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode(int x) : val(x), next(NULL) {}
7
+ * };
8
+ */
9
+class Solution {
10
+public:
11
+ ListNode *deleteDuplicates(ListNode *head) {
12
+ // Start typing your C/C++ solution below
13
+ // DO NOT write int main() function
14
+
15
+ if (head == NULL)
16
+ return NULL;
17
18
+ ListNode *prev = head;
19
+ ListNode *node = head->next;
20
21
+ while (node != NULL) {
22
+ if (node->val == prev->val) {
23
+ ListNode *dele = node;
24
+ prev->next = NULL;
25
+ node = node->next;
26
+ delete dele;
27
+ }
28
+ else {
29
+ prev->next = node;
30
+ prev = prev->next;
31
32
33
34
+ return head;
35
36
+};
0 commit comments