Movatterモバイル変換


[0]ホーム

URL:


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

Commitec3b19f

Browse files
refactor 83
1 parent20610bd commitec3b19f

File tree

1 file changed

+22
-31
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+22
-31
lines changed

‎src/main/java/com/fishercoder/solutions/_83.java

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@
22

33
importcom.fishercoder.common.classes.ListNode;
44

5-
/**
6-
* 83. Remove Duplicates from Sorted List
7-
*
8-
* Given a sorted linked list, delete all duplicates such that each element appear only once.
9-
10-
For example,
11-
Given 1->1->2, return 1->2.
12-
Given 1->1->2->3->3, return 1->2->3.
13-
*/
145
publicclass_83 {
15-
publicstaticclassSolution1 {
16-
publicListNodedeleteDuplicates(ListNodehead) {
17-
ListNoderet =newListNode(-1);
18-
ret.next =head;
19-
while (head !=null) {
20-
while (head.next !=null &&head.next.val ==head.val) {
21-
head.next =head.next.next;
6+
publicstaticclassSolution1 {
7+
publicListNodedeleteDuplicates(ListNodehead) {
8+
ListNoderet =newListNode(-1);
9+
ret.next =head;
10+
while (head !=null) {
11+
while (head.next !=null &&head.next.val ==head.val) {
12+
head.next =head.next.next;
13+
}
14+
head =head.next;
15+
}
16+
returnret.next;
2217
}
23-
head =head.next;
24-
}
25-
returnret.next;
2618
}
27-
}
2819

29-
publicstaticclassSolution2 {
30-
publicListNodedeleteDuplicates(ListNodehead) {
31-
ListNodecurr =head;
32-
while (curr !=null &&curr.next !=null) {
33-
if (curr.val ==curr.next.val) {
34-
curr.next =curr.next.next;
35-
}else {
36-
curr =curr.next;
20+
publicstaticclassSolution2 {
21+
publicListNodedeleteDuplicates(ListNodehead) {
22+
ListNodecurr =head;
23+
while (curr !=null &&curr.next !=null) {
24+
if (curr.val ==curr.next.val) {
25+
curr.next =curr.next.next;
26+
}else {
27+
curr =curr.next;
28+
}
29+
}
30+
returnhead;
3731
}
38-
}
39-
returnhead;
4032
}
41-
}
4233
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp