File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ import utils .CommonUtils ;
4
+ import classes .ListNode ;
5
+
6
+ public class RemoveDuplicatesfromSortedList {
7
+
8
+ public static ListNode deleteDuplicates (ListNode head ) {
9
+ ListNode ret = new ListNode (-1 );
10
+ ret .next = head ;
11
+ while (head != null ){
12
+ while (head .next != null && head .next .val == head .val ){
13
+ head .next = head .next .next ;
14
+ }
15
+ head = head .next ;
16
+ }
17
+ return ret .next ;
18
+ }
19
+
20
+ public static void main (String ...strings ){
21
+ ListNode head = new ListNode (1 );
22
+ head .next = new ListNode (1 );
23
+ head .next .next = new ListNode (2 );
24
+ head .next .next .next = new ListNode (3 );
25
+ head .next .next .next .next = new ListNode (3 );
26
+ CommonUtils .printList (head );
27
+ ListNode result = deleteDuplicates (head );
28
+ CommonUtils .printList (result );
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments