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 ...
随机推荐
- 本地化,将cancel替换成"取消"
在工程文件中选info,添加下面内容
- 在LoadRunner中进行Base64的编码和解码
<Base64 Encode/Decode for LoadRunner>这篇文章介绍了如何在LoadRunner中对字符串进行Base64的编码和解码: http://ptfrontli ...
- java String->float,float->int
类型转换代码 : String sourceStr = "0.0"; String类型 float sourceF = Float.valueOf(sourceStr); floa ...
- 【VBA编程】06.控制语句
[IF...THEN...语句] If condition Then [statements1] else [statements2] end if condition 为一个逻辑表达式,表示做选择时 ...
- struts过滤器的原理
struts就是充当拦截器(过滤器)的作用.在web.xml配置过滤器, package cn.itcast.framework.core; import java.io.IOException; i ...
- HTML5&CSS3初学者指南
介绍 网络时代已经到来.现在对人们来说,每天上网冲浪已经成为一种最为常见的行为. 一个典型的网页是由文本.图像和链接组成的.除去内容上的差异,不同网站的网页也具有不同的外观和感受,以实现在网络上建立自 ...
- unity, itween 对不透明对象使用FadeTo需要先更换material
跟自己实现fade一样,使用itween对不透明对象FadeTo前也要先更换material为透明material. 设player的Hierarchy如下: player --aniRoot --- ...
- G1日志分析
1. 概述 来自对官方G1垃圾收集器的日志解释分析,官方地址:https://blogs.oracle.com/poonam/understanding-g1-gc-logs或https://blog ...
- APK反编译之一:基础知识
作者:lpohvbe | http://blog.csdn.net/lpohvbe/article/details/7981386 这部分涉及的内容比较多,我会尽量从最基础开始说起,但需要读者一定的a ...
- redis命令_SETEX
SETEX key seconds value 将值 value 关联到 key ,并将 key 的生存时间设为 seconds (以秒为单位). 如果 key 已经存在, SETEX 命令将覆写旧值 ...