Skip to content

Commit 14844a1

Browse files
author
pangyanhao
committed
第一周第一道题
1 parent 50a875e commit 14844a1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Week_01/id_9/LeetCode_83_9.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

0 commit comments

Comments
 (0)