Skip to content

Commit 83dbeb4

Browse files
add 2154
1 parent ffbd96a commit 83dbeb4

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

README.md

+1
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||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2154 {
7+
public static class Solution1 {
8+
public int findFinalValue(int[] nums, int original) {
9+
Set<Integer> set = new HashSet<>();
10+
for (int num : nums) {
11+
set.add(num);
12+
}
13+
while (set.contains(original)) {
14+
original *= 2;
15+
}
16+
return original;
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2145;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2145Test {
10+
private static _2145.Solution1 solution1;
11+
private static int[] differences;
12+
private static int lower;
13+
private static int upper;
14+
private static int expected;
15+
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _2145.Solution1();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
differences = new int[]{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+
public void test2() {
32+
differences = new int[]{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+
public void test3() {
41+
differences = new int[]{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+
public void test4() {
50+
differences = new int[]{-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+
public void test5() {
59+
differences = new int[]{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)