视频分析:

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. canvas锯齿

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. 基于Qt的A*算法可视化分析

    代码地址如下:http://www.demodashi.com/demo/13677.html 需求 之前做过一个无人车需要自主寻找最佳路径,所以研究了相关的寻路算法,最终选择A算法,因为其简单易懂, ...

  3. String、StringBuilder、StringBuffer对比

    参考:http://swiftlet.net/archives/1694 http://www.cnblogs.com/springcsc/archive/2009/12/03/1616326.htm ...

  4. java基础讲解07-----数组

    1.什么是数组 2.怎么使用数组 package test; public class ShuZu {            public static void main(String[] args ...

  5. STL容器分析--queue

    queue,顾名思义,是指队列.满足先进先出的原则.

  6. winform最小化及关闭提示

    public PrintService() { InitializeComponent(); this.WindowState = FormWindowState.Minimized; } priva ...

  7. CentOS7 安装lua环境(我是在mysql读写分离用的)

    下载地址:http://www.lua.org/download.html 安装方法: 依次执行以下命令: curl -R -O http://www.lua.org/ftp/lua-5.3.1.ta ...

  8. 点滴积累【JS】---JS小功能(onmousedown实现鼠标拖拽div移动)

    效果: 思路: 利用onmousedown事件实现拖拽.首先获得鼠标横坐标点和纵坐标点到div的距离,然后当鼠标移动后再用可视区的距离减去横纵坐标与div的距离.然后在判断不让DIV移出可视区,然后再 ...

  9. QTP 无法识别web 大全

    说明:这里以一个登陆框为例,展示了各种方式供你选择. 假设你喜欢对象的话.也能够手动加入对象webedit. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv ...

  10. Visual Studio 环境配置

    一.Productivity Power Tools 1.安装了之后有垂直的分隔线,取消 2.高亮选中匹配的代码 ① VS 2012 3.高亮当前的Tab选项卡