Skip to content

Commit ad93a14

Browse files
committed
Fixed sonar warning.
1 parent 7feac33 commit ad93a14

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/g0301_0400/s0352_data_stream_as_disjoint_intervals/SummaryRanges.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public Node(int val) {
2121
}
2222
}
2323

24-
List<Node> list;
25-
// Initialize your data structure here.
24+
private List<Node> list;
25+
2626
public SummaryRanges() {
2727
list = new ArrayList<>();
2828
}
@@ -47,20 +47,22 @@ public void addNum(int val) {
4747
}
4848

4949
public int[][] getIntervals() {
50-
for (int i = 1; i < list.size(); i++) {
50+
int i = 1;
51+
while (i < list.size()) {
5152
Node prev = list.get(i - 1);
5253
Node curr = list.get(i);
5354
if (curr.min == prev.max + 1) {
5455
prev.max = curr.max;
5556
list.remove(i--);
5657
}
58+
i++;
5759
}
5860
int len = list.size();
5961
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;
6466
}
6567
return res;
6668
}

0 commit comments

Comments
 (0)