Skip to content

Commit dfa23bd

Browse files
authored
Create add-minimum-number-of-rungs.py
1 parent 6bbbbb9 commit dfa23bd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/add-minimum-number-of-rungs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def addRungs(self, rungs, dist):
6+
"""
7+
:type rungs: List[int]
8+
:type dist: int
9+
:rtype: int
10+
"""
11+
def ceil_divide(a, b):
12+
return (a+(b-1))//b
13+
14+
result = prev = 0
15+
for curr in rungs:
16+
result += ceil_divide(curr-prev, dist)-1
17+
prev = curr
18+
return result

0 commit comments

Comments
 (0)