Skip to content

Commit 92cf51a

Browse files
committed
Add Solution2.java for 0083.Remove Duplicates from Sorted List
1 parent 4ca4ecf commit 92cf51a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
class Solution {
10+
public ListNode deleteDuplicates(ListNode head) {
11+
ListNode current = head;
12+
while (current != null && current.next != null) {
13+
if (current.next.val == current.val) {
14+
current.next = current.next.next;
15+
} else {
16+
current = current.next;
17+
}
18+
}
19+
return head;
20+
}
21+
}

0 commit comments

Comments
 (0)