Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 92cf51a

Browse files
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
Lines changed: 21 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /