博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LintCode 简单】749. John's backyard garden
阅读量:4088 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
[转]打印质数的各种算法
查看>>
[转]javascript with延伸的作用域是只读的吗?
查看>>
php的autoload与global
查看>>
IE不支持option的display:none属性
查看>>
[分享]mysql内置用于字符串型ip地址和整数型ip地址转换函数
查看>>
[转]开源中最好的Web开发的资源
查看>>
Https加密及攻防
查看>>
Java生成随机不重复推广码邀请码
查看>>
【JAVA数据结构】双向链表
查看>>
【JAVA数据结构】先进先出队列
查看>>
String类的intern方法随笔
查看>>
【泛型】一个简易的对象间转换的工具类(DO转VO)
查看>>
1.随机函数,计算机运行的基石
查看>>
MouseEvent的e.stageX是Number型,可见as3作者的考虑
查看>>
移植Vim配色方案到Eclipse
查看>>
从超链接调用ActionScript
查看>>
谈谈加密和混淆吧[转]
查看>>
TCP的几个状态对于我们分析所起的作用SYN, FIN, ACK, PSH,
查看>>
网络游戏客户端的日志输出
查看>>
关于按钮的mouseOver和rollOver
查看>>