Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6bd9521 commit e961b90Copy full SHA for e961b90
1326.灌溉花园的最少水龙头数目/1326-灌溉花园的最少水龙头数目.py
@@ -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