File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace ProblemSolutions
8
+ {
9
+ public class Problem083 : IProblem
10
+ {
11
+ public class ListNode
12
+ {
13
+ public int val ;
14
+ public ListNode next ;
15
+ public ListNode ( int x ) { val = x ; }
16
+ }
17
+
18
+ public void RunProblem ( )
19
+ {
20
+ throw new NotImplementedException ( ) ;
21
+ }
22
+
23
+ public ListNode DeleteDuplicates ( ListNode head )
24
+ {
25
+ /*
26
+ * 当前结点,是在遍历的过程中做检测,是该移动一步,还是该排除掉一个重复的情况
27
+ * 单链表基本操作的数量程度
28
+ * 时间复杂度:O(n),只是一次单链表的遍历
29
+ * 空间复杂度:O(1),使用的存储空间是固定的
30
+ */
31
+
32
+ ListNode cur = head ;
33
+
34
+ while ( cur != null && cur . next != null )
35
+ {
36
+ if ( cur . val != cur . next . val )
37
+ {
38
+ cur = cur . next ;
39
+ continue ;
40
+ }
41
+
42
+ cur . next = cur . next . next ;
43
+ }
44
+
45
+ return head ;
46
+ }
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments