Skip to content

Commit ffe1708

Browse files
committed
2020-01-22
1 parent e961b90 commit ffe1708

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution(object):
2+
def maximum69Number (self, num):
3+
"""
4+
:type num: int
5+
:rtype: int
6+
"""
7+
return int(str(num).replace("6", "9", 1))

1326.灌溉花园的最少水龙头数目/1326-灌溉花园的最少水龙头数目.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ def minTaps(self, n, ranges):
88
ivls = []
99
reach = [0 for _ in range(n + 1)]
1010
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-
11+
start, end = max(i - ranges[i], 0), min(i + ranges[i], n + 1)
1512
for j in range(start, end):
1613
reach[j] = max(end, reach[j])
1714

1815
res = 0
1916
pos = 0
2017
while pos < n:
21-
if reach[pos] <= pos:
18+
if reach[pos] <= pos: # 无法继续抵达更远的位置
2219
return -1
2320
pos = reach[pos]
2421
res += 1
25-
return res
26-
22+
return res

0 commit comments

Comments
 (0)