We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61a30f4 commit b0f17caCopy full SHA for b0f17ca
83/step1.cpp
@@ -0,0 +1,26 @@
1
+/**
2
+4:30
3
+Time: O(N)
4
+Space: O(1)
5
+
6
+リストの性質上、削除すべき要素は隣接している。
7
+リストを頭から終わりまでチェックし、不要要素を削除していくことで実現できると判断。
8
9
+ */
10
+class Solution {
11
+public:
12
+ ListNode* deleteDuplicates(ListNode* head) {
13
+ ListNode* current = head;
14
+ while (current) {
15
+ if (!current || !current->next) {
16
+ return head;
17
+ }
18
+ if (current->val == current->next->val) {
19
+ current->next = current->next->next;
20
+ } else {
21
+ current = current->next;
22
23
24
25
26
+};
0 commit comments