leetcode-happy number implemented in python
视频分析:
http://v.youku.com/v_show/id_XMTMyODkyNDA0MA==.html?from=y1.7-1.2
class Solution(object):
def isHappy(self, n):
if n==1:
return True
elif n==4:
return False
else:
return self.isHappy(self.Happy(n))
def Happy(self,n):
z=0
while n!=0:
d=n%10
z+=pow(d,2)
n=(n-n%10)//10
return z
def HappySeq(self,start,cnt):
tmp=start
print (tmp,end=' ')
for x in range(1, cnt):
tmp=self.Happy(tmp)
print (tmp,end=' ')
if tmp==4 or tmp==1:
break
leetcode-happy number implemented in python的更多相关文章
- LeetCode Single Number I II Python
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- [LeetCode] 200. Number of Islands 岛屿的数量
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- [LeetCode] 323. Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- C#版 - Leetcode 191. Number of 1 Bits-题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- [leetcode]200. Number of Islands岛屿个数
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- [leetcode]694. Number of Distinct Islands你究竟有几个异小岛?
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- [LeetCode] 711. Number of Distinct Islands II_hard tag: DFS
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- [LeetCode] 694. Number of Distinct Islands
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- 力不从心 Leetcode(ugly number heap) 263, 264,313
Leetcode ugly number set (3 now) new ugly number is generated by multiplying a prime with previous g ...
随机推荐
- iOS工程中的info.plist文件的完整研究
原地址:http://blog.sina.com.cn/s/blog_947c4a9f0100zf41.html 们建立一个工程后,会在Supporting files下面看到一个"工程名- ...
- mysql 取字段内容的第一个字符并大写
update words set `indexkey` = UPPER(left(word,1)) mysql 取字段内容的第一个字符并大写 用到两个mysql函数: 转换为大写:upper( ) 截 ...
- js 终止 forEach 循环
1.因为 forEach() 无法通过正常流程终止,所以可以通过抛出异常的方式实现终止. try{ var array = ["first","second", ...
- 利用socket.io+nodejs打造简单聊天室
代码地址如下:http://www.demodashi.com/demo/11579.html 界面展示: 首先展示demo的结果界面,只是简单消息的发送和接收,包括发送文字和发送图片. ws说明: ...
- winfrom cahce 问题
.Clear()不能随便用 .Clear()的比较没有什么意思,因为只是把DataTable清空而已,在堆中任然分配内存,一般要比较也是比较Close()方法,不过DataTable没有这个方法 至于 ...
- LAMP架构三
PHP相关配置 1.查找php配置文件/usr/local/php/bin/php -i或者phpinfo() [root@bogon admin]# /usr/local/php/bin/php - ...
- IOS 通过界面图标启动Web应用 + 全屏应用 + 添加到主屏幕
请注意!!!使用了[全屏模式之后].页面的顶部会空出一大块.而且这并不属于margin,padding,或者定位.就是单纯的空出来非常难调试.其实坑就是这里 在 iPhone「添加到主屏幕」时显示自定 ...
- .Net并行编程高级教程(二)-- 任务并行
前面一篇提到例子都是数据并行,但这并不是并行化的唯一形式,在.Net4之前,必须要创建多个线程或者线程池来利用多核技术.现在只需要使用新的Task实例就可以通过更简单的代码解决命令式任务并行问题. 1 ...
- ui-router参数传递
基本参数: ‘/user/:id' '/user/{id}' '/user/{id:int}' 使用正则表达式: '/user/{id:[0-9]{1,8}' '/user/{id:.*}' '/us ...
- vivado设计一:建立第一个入门工程(基于zybo)
vivado设计一:建立第一个入门工程(基于zybo) 0赞 发表于 2014/6/17 23:03:25 阅读(8777) 评论(4) 软件:vivado 2013.4 电脑:xp系统 硬件:zyb ...