File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/main/java/g0301_0400/s0352_data_stream_as_disjoint_intervals Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ public Node(int val) {
21
21
}
22
22
}
23
23
24
- List <Node > list ;
25
- // Initialize your data structure here.
24
+ private List <Node > list ;
25
+
26
26
public SummaryRanges () {
27
27
list = new ArrayList <>();
28
28
}
@@ -47,20 +47,22 @@ public void addNum(int val) {
47
47
}
48
48
49
49
public int [][] getIntervals () {
50
- for (int i = 1 ; i < list .size (); i ++) {
50
+ int i = 1 ;
51
+ while (i < list .size ()) {
51
52
Node prev = list .get (i - 1 );
52
53
Node curr = list .get (i );
53
54
if (curr .min == prev .max + 1 ) {
54
55
prev .max = curr .max ;
55
56
list .remove (i --);
56
57
}
58
+ i ++;
57
59
}
58
60
int len = list .size ();
59
61
int [][] res = new int [len ][2 ];
60
- for (int i = 0 ; i < len ; i ++) {
61
- Node node = list .get (i );
62
- res [i ][0 ] = node .min ;
63
- res [i ][1 ] = node .max ;
62
+ for (int j = 0 ; j < len ; j ++) {
63
+ Node node = list .get (j );
64
+ res [j ][0 ] = node .min ;
65
+ res [j ][1 ] = node .max ;
64
66
}
65
67
return res ;
66
68
}
You can’t perform that action at this time.
0 commit comments