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

Commit83dbeb4

Browse files
add 2154
1 parentffbd96a commit83dbeb4

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-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+
|2154|[Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2154.java)||Easy||
1112
|2150|[Find All Lonely Numbers in the Array](https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2150.java)||Medium||
1213
|2149|[Rearrange Array Elements by Sign](https://leetcode.com/problems/rearrange-array-elements-by-sign/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2149.java)||Medium||
1314
|2148|[Count Elements With Strictly Smaller and Greater Elements](https://leetcode.com/problems/count-elements-with-strictly-smaller-and-greater-elements/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2148.java)||Easy||
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_2154 {
7+
publicstaticclassSolution1 {
8+
publicintfindFinalValue(int[]nums,intoriginal) {
9+
Set<Integer>set =newHashSet<>();
10+
for (intnum :nums) {
11+
set.add(num);
12+
}
13+
while (set.contains(original)) {
14+
original *=2;
15+
}
16+
returnoriginal;
17+
}
18+
}
19+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2145;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2145Test {
10+
privatestatic_2145.Solution1solution1;
11+
privatestaticint[]differences;
12+
privatestaticintlower;
13+
privatestaticintupper;
14+
privatestaticintexpected;
15+
16+
@BeforeClass
17+
publicstaticvoidsetup() {
18+
solution1 =new_2145.Solution1();
19+
}
20+
21+
@Test
22+
publicvoidtest1() {
23+
differences =newint[]{1, -3,4};
24+
lower =1;
25+
upper =6;
26+
expected =2;
27+
assertEquals(expected,solution1.numberOfArrays(differences,lower,upper));
28+
}
29+
30+
@Test
31+
publicvoidtest2() {
32+
differences =newint[]{3, -4,5,1, -2};
33+
lower = -4;
34+
upper =5;
35+
expected =4;
36+
assertEquals(expected,solution1.numberOfArrays(differences,lower,upper));
37+
}
38+
39+
@Test
40+
publicvoidtest3() {
41+
differences =newint[]{4, -7,2};
42+
lower =3;
43+
upper =6;
44+
expected =0;
45+
assertEquals(expected,solution1.numberOfArrays(differences,lower,upper));
46+
}
47+
48+
@Test
49+
publicvoidtest4() {
50+
differences =newint[]{-97793,95035,79372, -41294, -90060, -57485,28899, -83385, -64425};
51+
lower = -99340;
52+
upper = -1477;
53+
expected =0;
54+
assertEquals(expected,solution1.numberOfArrays(differences,lower,upper));
55+
}
56+
57+
@Test
58+
publicvoidtest5() {
59+
differences =newint[]{23263, -3868, -24260, -11705};
60+
lower = -26206;
61+
upper =23564;
62+
expected =9938;
63+
assertEquals(expected,solution1.numberOfArrays(differences,lower,upper));
64+
}
65+
66+
67+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp