Skip to content

Commit 75c7499

Browse files
refactor 352
1 parent 7e15f7c commit 75c7499

File tree

1 file changed

+3
-19
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-19
lines changed

src/main/java/com/fishercoder/solutions/_352.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
import java.util.List;
77
import java.util.TreeMap;
88

9-
/**
10-
* 352. Data Stream as Disjoint Intervals
11-
*
12-
* Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals.
13-
14-
For example, suppose the integers from the data stream are 1, 3, 7, 2, 6, ..., then the summary will be:
15-
16-
[1, 1]
17-
[1, 1], [3, 3]
18-
[1, 1], [3, 3], [7, 7]
19-
[1, 3], [7, 7]
20-
[1, 3], [6, 7]
21-
22-
Follow up:
23-
What if there are lots of merges and the number of disjoint intervals are small compared to the data stream's size?
24-
*/
259
public class _352 {
2610

2711
public static class Solution1 {
@@ -46,9 +30,9 @@ public void addNum(int val) {
4630
Integer lower = treeMap.lowerKey(val);
4731
Integer higher = treeMap.higherKey(val);
4832
if (lower != null
49-
&& higher != null
50-
&& treeMap.get(lower).end + 1 == val
51-
&& higher == val + 1) {
33+
&& higher != null
34+
&& treeMap.get(lower).end + 1 == val
35+
&& higher == val + 1) {
5236
treeMap.get(lower).end = treeMap.get(higher).end;
5337
treeMap.remove(higher);
5438
} else if (lower != null && treeMap.get(lower).end + 1 >= val) {

0 commit comments

Comments
 (0)