视频分析:

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的更多相关文章

  1. LeetCode Single Number I II Python

    Single Number Given an array of integers, every element appears twice except for one. Find that sing ...

  2. [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 ...

  3. [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), ...

  4. C#版 - Leetcode 191. Number of 1 Bits-题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  5. [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 ...

  6. [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 ...

  7. [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 ...

  8. [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 ...

  9. 力不从心 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 ...

随机推荐

  1. 算法笔记_160:算法提高 约数个数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 输入一个正整数N (1 样例输入 12 样例输出 6 样例说明 12的约数包括:1,2,3,4,6,12.共6个 2 解决方案 具体代码如下: im ...

  2. RMQ 算法入门

    1. 概述 RMQ(Range Minimum/Maximum Query).即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A ...

  3. logback 配置解析

    http://www.cnblogs.com/cb0327/p/5759441.html 正文 回到顶部 1.根节点<configuration>包含的属性 scan: 当此属性设置为tr ...

  4. 【BIEE】MDS-01377:无法从使用 JNDI 名称 “jdbc/mds/owsm” 配置的数据源获取数据库连接

    这是一次意外关机情况,BIEE环境是window server2008,但是一次意外情况,BIEE自动关机了,造成开启成功新启动BIEE产生如下错误: 错误产生后,倒腾了半天,并没发现什么问题,只是通 ...

  5. LoadRunner+Android模所器实现抓包并调试本地服务端

    步骤就是 1:新建LR脚本.协议选择Mobile Application - HTTP/HTML 2:在record里选择第三个:Record Emulator........ 3:  选择下一步后, ...

  6. 全排列算法 --javascript 实现

    var Ann = function a(arr){ if(arr.length == 1){return arr;} var rr = new Array(); for(var i = 0; i&l ...

  7. 织梦dedecms修改include和plus重命名提高安全性防漏洞注入挂马

    织梦dedecms是新手站长使用得比较多的一个建站开源程序,正因如此,也是被被入侵挂马比较多的程序.下面就来跟大家说一下怎么重新命名dedecms的include文件夹以及plus文件夹来提高网站的安 ...

  8. linux c++ 文件获取md5

    当前在linux系统下,shell命令可以获取md5值,如下: 如果进行c++编程,在代码里执行shell命令可以获得,但是很不雅观,特别是了解了system或者popen函数的机制之后.现在介绍使用 ...

  9. ConcurrentBag同线程元素的添加和删除

    https://www.mgenware.com/blog/?p=232 ConcurrentBag<T>对于同一个线程值的添加和删除是非常快的,因为ConcurrentBag内部将数据按 ...

  10. FreeSWITCH小结:关于export的原理介绍及应用

    FreeSWITCH小结:关于export的原理介绍及应用 Export原理 普通export用法 在dialplan中经常会用到export,如下所示: <action application ...