Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e961b90

Browse files
committed
2020-01-22
1 parent 6bd9521 commit e961b90

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution(object):
2+
def minTaps(self, n, ranges):
3+
"""
4+
:type n: int
5+
:type ranges: List[int]
6+
:rtype: int
7+
"""
8+
ivls = []
9+
reach = [0 for _ in range(n + 1)]
10+
for i in range(n + 1):
11+
start, end = i - ranges[i], i + ranges[i]
12+
end = min(end, n + 1)
13+
start = max(start, 0)
14+
15+
for j in range(start, end):
16+
reach[j] = max(end, reach[j])
17+
18+
res = 0
19+
pos = 0
20+
while pos < n:
21+
if reach[pos] <= pos:
22+
return -1
23+
pos = reach[pos]
24+
res += 1
25+
return res
26+

0 commit comments

Comments
 (0)