forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path_83.java
More file actions
23 lines (19 loc) · 641 Bytes
/
_83.java
File metadata and controls
23 lines (19 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.fishercoder.solutions;
import com.fishercoder.common.classes.ListNode;
/**Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.*/
public class _83 {
public static ListNode deleteDuplicates(ListNode head) {
ListNode ret = new ListNode(-1);
ret.next = head;
while (head != null) {
while (head.next != null && head.next.val == head.val) {
head.next = head.next.next;
}
head = head.next;
}
return ret.next;
}
}