Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca1fcd8

Browse files
add 1656
1 parent41b4b16 commitca1fcd8

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java)||Easy|Array, Design|
1112
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java)||Easy|Array|
1213
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java)||Easy|Array, Sort|
1314
|1637|[Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/)|[Javascript](./javascript/_1637.js)|| Medium| Sort|
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
importjava.util.TreeMap;
6+
7+
publicclass_1656 {
8+
publicstaticclassSolution1 {
9+
publicstaticclassOrderedStream {
10+
TreeMap<Integer,String>map;
11+
intptr;
12+
intlimit;
13+
14+
publicOrderedStream(intn) {
15+
this.map =newTreeMap<>();
16+
this.ptr =1;
17+
this.limit =n;
18+
}
19+
20+
publicList<String>insert(intid,Stringvalue) {
21+
map.put(id,value);
22+
List<String>result =newArrayList<>();
23+
if (map.containsKey(ptr)) {
24+
for (intkey =ptr;key <=limit;key++) {
25+
if (map.containsKey(key)) {
26+
result.add(map.get(key));
27+
}else {
28+
break;
29+
}
30+
}
31+
inti =id;
32+
while (map.containsKey(i)) {
33+
i++;
34+
}
35+
ptr =i;
36+
}
37+
returnresult;
38+
}
39+
}
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1656;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importjava.util.Arrays;
8+
importjava.util.Collections;
9+
10+
importstaticorg.junit.Assert.assertArrayEquals;
11+
importstaticorg.junit.Assert.assertEquals;
12+
13+
publicclass_1656Test {
14+
privatestatic_1656.Solution1.OrderedStreamorderedStream;
15+
16+
@Test
17+
publicvoidtest1() {
18+
orderedStream =new_1656.Solution1.OrderedStream(5);
19+
assertEquals(Collections.emptyList(),orderedStream.insert(3,"ccccc"));
20+
assertEquals(Arrays.asList("aaaaa"),orderedStream.insert(1,"aaaaa"));
21+
assertEquals(Arrays.asList("bbbbb","ccccc"),orderedStream.insert(2,"bbbbb"));
22+
assertEquals(Collections.emptyList(),orderedStream.insert(5,"eeeee"));
23+
assertEquals(Arrays.asList("ddddd","eeeee"),orderedStream.insert(4,"ddddd"));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp