Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
46 lines (43 loc) · 1.05 KB

File metadata and controls

46 lines (43 loc) · 1.05 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode deleteDuplication(ListNode pHead)
{
//head为null
if(pHead==null)
return null;
if(pHead.next==null)
return pHead;
//临时的头结点
ListNode root=new ListNode(0);
root.next = pHead;
//记录前驱节点
ListNode prev = root;
//记录前驱节点
ListNode node = pHead;
while(node!=null&&node.next!=null)
{
//有重复节点,与node值相同的节点都要删除
if(node.val==node.next.val){
while(node.next!=null &&node.next.val==node.val)
{
node = node.next;
}
prev.next=node.next;
}
else{
prev.next= node;
prev=prev.next;
}
node=node.next;
}
return root.next;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.