Skip to content

Commit 7e0198d

Browse files
committed
add lintcode 1699
1 parent fda1653 commit 7e0198d

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ LintCode|74 | 第一个错误的代码版本 | 一刷无bug |
1313
LintCode|75 | 寻找峰值 | 一刷有点小问题 |
1414
LintCode|159|寻找旋转排序数组中的最小值|一刷无bug|
1515
LintCode|160|寻找旋转排序数组中的最小值 II|有大量重复元素|
16-
LintCode|585 | 山脉序列中的最大值 | 一刷无bug |
16+
LintCode|585 | 山脉序列中的最大值 | 一刷无bug |
17+
LintCode|1699 | 建庙 | 二分法的变形 |

python/lintcode_1669.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
"""
3+
@param m: m pillars of your temple.
4+
@param woods: length of n different wood
5+
@return: return the maximum height of the temple.
6+
"""
7+
8+
def buildTemple(self, m, woods):
9+
# write your code here.
10+
if m < 1 or len(woods) < 1:
11+
return 0
12+
start = min(woods)
13+
end = max(woods)
14+
while start + 1 < end:
15+
mid = start + (end - start) // 2
16+
if self.helper(woods, mid) < m:
17+
end = mid
18+
else:
19+
start = mid
20+
if self.helper(woods, start) >= m:
21+
return start
22+
else:
23+
return end
24+
25+
def helper(self, woods, eachlen):
26+
count = 0
27+
for wood in woods:
28+
count = count + wood // eachlen
29+
return count

0 commit comments

Comments
 (0)