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

Commit2e5b07a

Browse files
add 1936
1 parentb88fa85 commit2e5b07a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-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 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|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1936 {
4+
publicstaticclassSolution1 {
5+
publicintaddRungs(int[]rungs,intdist) {
6+
intaddons =0;
7+
intcurrentHeight =0;
8+
for (inti =0;i <rungs.length; ) {
9+
intnextRung =rungs[i];
10+
if (nextRung -currentHeight <=dist) {
11+
currentHeight =nextRung;
12+
i++;
13+
}else {
14+
intadds = (nextRung -currentHeight -1) /dist;
15+
addons +=adds;
16+
currentHeight +=dist *adds;
17+
}
18+
}
19+
returnaddons;
20+
}
21+
}
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1936;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1936Test {
10+
privatestatic_1936.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1936.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(2,solution1.addRungs(newint[]{3},1));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(2,solution1.addRungs(newint[]{1,3,5,10},2));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(0,solution1.addRungs(newint[]{3,6,8,10},3));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(1,solution1.addRungs(newint[]{3,4,6,7},2));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(0,solution1.addRungs(newint[]{5},10));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp