Skip to content

Commit f03b198

Browse files
committed
1936. 新增的最少台阶数
1 parent 474a21b commit f03b198

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.gatsby;
2+
3+
/**
4+
* @ClassName: _1936AddMinimumNumberOfRungs
5+
* @Description: 1936. Add Minimum Number of Rungs
6+
* @author: Gatsby
7+
* @date: 2022/7/29 11:44
8+
*/
9+
10+
public class _1936AddMinimumNumberOfRungs {
11+
12+
public int addRungs(int[] rungs, int dist) {
13+
int res = 0;
14+
int cur = 0;
15+
for (int i = 0; i < rungs.length; ++i) {
16+
int dis = rungs[i] - cur;
17+
if (dis > dist) res += (dis - 1) / dist;
18+
cur = rungs[i];
19+
}
20+
return res;
21+
}
22+
}
23+
24+

0 commit comments

Comments
 (0)