本文共 979 字,大约阅读时间需要 3 分钟。
1.问题描述:
John wants to build a back garden on the empty space behind his home. There are two kinds of bricks now, one is 3
dm high and the other is 7
dm high. John wants to enclose a high x
dm wall. If John can do this, output YES, otherwise NO.
2.样例:
Give x = 10
,return YES
.
Explanation:x = 3 + 7:That is, you need one batch of 3 dm height bricks and one batch of 7 dm height bricks.
Give x = 5
,return NO
.
Explanation:John can not enclose a high 5 dm wall with 3 dm height bricks and 7 dm height bricks.
Give x = 13
,return YES
.
Explanation:x = 2 * 3 + 7:That is, you need two batch of 3 dm height bricks and one batch of 7 dm height bricks.
3.代码:
class Solution: """ @param x: the wall's height @return: YES or NO """ def isBuild(self, x): # Write your code here if x<0: return "NO" if x%3 ==0 or x %7 ==0 : return "YES" else: a=x-3 b=x-7 return self.isBuild(a) and self.isBuild(b)
转载地址:http://hauii.baihongyu.com/