Skip to content

Commit 2e5b07a

Browse files
add 1936
1 parent b88fa85 commit 2e5b07a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-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 1
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1936|[Add Minimum Number of Rungs](https://leetcode.com/problems/add-minimum-number-of-rungs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1936.java) ||Medium||
1112
|1935|[Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1935.java) ||Easy|String|
1213
|1929|[Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1929.java) ||Easy||
1314
|1926|[Nearest Exit from Entrance in Maze](https://leetcode.com/problems/nearest-exit-from-entrance-in-maze/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1926.java) ||Medium|DP, DFS, BFS|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1936 {
4+
public static class Solution1 {
5+
public int addRungs(int[] rungs, int dist) {
6+
int addons = 0;
7+
int currentHeight = 0;
8+
for (int i = 0; i < rungs.length; ) {
9+
int nextRung = rungs[i];
10+
if (nextRung - currentHeight <= dist) {
11+
currentHeight = nextRung;
12+
i++;
13+
} else {
14+
int adds = (nextRung - currentHeight - 1) / dist;
15+
addons += adds;
16+
currentHeight += dist * adds;
17+
}
18+
}
19+
return addons;
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1936;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1936Test {
10+
private static _1936.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1936.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.addRungs(new int[]{3}, 1));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(2, solution1.addRungs(new int[]{1, 3, 5, 10}, 2));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(0, solution1.addRungs(new int[]{3, 6, 8, 10}, 3));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertEquals(1, solution1.addRungs(new int[]{3, 4, 6, 7}, 2));
35+
}
36+
37+
@Test
38+
public void test5() {
39+
assertEquals(0, solution1.addRungs(new int[]{5}, 10));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)