File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed
main/java/com/stevesun/solutions Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 1
1
package com .stevesun .solutions ;
2
2
3
3
import com .stevesun .common .classes .ListNode ;
4
- import com .stevesun .common .utils .CommonUtils ;
5
4
6
5
/**Given a sorted linked list, delete all duplicates such that each element appear only once.
7
6
@@ -21,15 +20,4 @@ public static ListNode deleteDuplicates(ListNode head) {
21
20
}
22
21
return ret .next ;
23
22
}
24
-
25
- public static void main (String ...strings ){
26
- ListNode head = new ListNode (1 );
27
- head .next = new ListNode (1 );
28
- head .next .next = new ListNode (2 );
29
- head .next .next .next = new ListNode (3 );
30
- head .next .next .next .next = new ListNode (3 );
31
- CommonUtils .printList (head );
32
- ListNode result = deleteDuplicates (head );
33
- CommonUtils .printList (result );
34
- }
35
23
}
Original file line number Diff line number Diff line change
1
+ package com .stevesun ;
2
+
3
+ import com .stevesun .common .classes .ListNode ;
4
+ import com .stevesun .solutions .RemoveDuplicatesfromSortedList ;
5
+ import org .junit .Assert ;
6
+ import org .junit .Test ;
7
+
8
+ /**
9
+ * Created by stevesun on 4/18/17.
10
+ */
11
+ public class RemoveDuplicatesfromSortedListTest {
12
+
13
+ @ Test
14
+ public void test1 () {
15
+ ListNode head = new ListNode (1 );
16
+ head .next = new ListNode (1 );
17
+ head .next .next = new ListNode (2 );
18
+ head .next .next .next = new ListNode (3 );
19
+ head .next .next .next .next = new ListNode (3 );
20
+
21
+ RemoveDuplicatesfromSortedList test = new RemoveDuplicatesfromSortedList ();
22
+
23
+ ListNode expected = new ListNode (1 );
24
+ expected .next = new ListNode (2 );
25
+ expected .next .next = new ListNode (3 );
26
+
27
+ Assert .assertEquals (expected , test .deleteDuplicates (head ));
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments