-
Notifications
You must be signed in to change notification settings - Fork 59
/
Solution.java
35 lines (32 loc) · 941 Bytes
/
Solution.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
34
35
package g0001_0100.s0083_remove_duplicates_from_sorted_list;
// #Easy #Linked_List #Data_Structure_I_Day_8_Linked_List
// #2022_06_20_Time_0_ms_(100.00%)_Space_44_MB_(64.59%)
import com_github_leetcode.ListNode;
/*
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if (head == null) {
return null;
}
ListNode current = head;
ListNode next = current.next;
while (null != next) {
if (current.val == next.val) {
current.next = next.next;
} else {
current = next;
}
next = current.next;
}
return head;
}
}