-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL83.java
More file actions
43 lines (37 loc) · 1008 Bytes
/
L83.java
File metadata and controls
43 lines (37 loc) · 1008 Bytes
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
package com.liang.leetcode;
import com.liang.leetcode.Interface.L83.ListNode;
/**
* @ClassName L83
* @description remove-duplicates-from-sorted-list
* @Author LiaNg
* @Date 2018/11/3
*/
public class L83 {
public static void main(String[] args) {
int[] input = new int[]{1, 1, 2, 3, 3};
ListNode listNode = ListNode.buildListNode(input);
L83 l = new L83();
l.deleteDuplicates(listNode);
while (listNode != null) {
System.out.println("val:" + listNode.val);
listNode = listNode.next;
}
}
/**
* 删除排序链表中的重复元素
*/
public ListNode deleteDuplicates(ListNode head) {
ListNode now = head;
if (now == null) {
return null;
}
while (now.next != null) {
if (now.val == now.next.val) {
now.next = now.next.next;
} else {
now = now.next;
}
}
return head;
}
}