forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_83.java
33 lines (30 loc) · 959 Bytes
/
_83.java
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
package com.fishercoder.solutions;
import com.fishercoder.common.classes.ListNode;
public class _83 {
public static class Solution1 {
public 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;
}
}
public static class Solution2 {
public ListNode deleteDuplicates(ListNode head) {
ListNode curr = head;
while (curr != null && curr.next != null) {
if (curr.val == curr.next.val) {
curr.next = curr.next.next;
} else {
curr = curr.next;
}
}
return head;
}
}
}