视频分析:

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. java.util.HashMap 解析

    HashMap 是我们经常使用的一种数据结构.工作中会经常用到,面试也会总提到这个数据结构,找工作的时候,”HashTable 和HashMap的区别“被问到过没有? 本文会从原理,JDK源码,项目使 ...

  2. 算法笔记_096:蓝桥杯练习 算法提高 求最大值(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 给n个有序整数对ai bi,你需要选择一些整数对 使得所有你选定的数的ai+bi的和最大.并且要求你选定的数对的ai之和非负,bi之和非负 ...

  3. ES6 编程风格

    1.块级作用域 (1)使用let代替var 好处:变量应该只在其声明的代码块内有效:var命令存在变量提升效用,let命令没有这个问题. (2)全局常量 在let和const之间,建议优先使用cons ...

  4. std::shared_ptr 和 std::weak_ptr的用法以及引用计数的循环引用问题

    在std::shared_ptr被引入之前,C++标准库中实现的用于管理资源的智能指针只有std::auto_ptr一个而已.std::auto_ptr的作用非常有限,因为它存在被管理资源的所有权转移 ...

  5. 【Windows】免费图片提取文字的方法

    今天意外的看到一个可以提取图片中文字的网站,自己试了下,提取效果还不错 网址为: https://zhcn.109876543210.com/ 现在有图片如下 我想从中提取的文字 1.打开网址,上传图 ...

  6. X86服务器、小型机、大型机、塔式、机架式、刀片式服务器、工作站

    ü  服务器分:x86(PC)服务器,小型机(Unix服务器),大型机: pc服务器则主要指基于intel处理器的x86架构,是一个通用开放的系统. UNIX服务器,也就是中国业内习惯上说的小型机,在 ...

  7. node.js零基础详细教程(6):mongodb数据库操作 以及导入导出

    第六章 建议学习时间4小时  课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑. ...

  8. join和countDownLatch原理及区别详解

    先上结论 原理 join 原理:在当前线程中调用另一个线程线程 thread 的 join() 方法时,会调用该 thread 的 wait() 方法,直到这个 thread 执行完毕(JVM在 ru ...

  9. unity, unlit surface shader (texColor only surface shader)

    要实现双面透明无光照只有纹理色的surface shader. 错误的写法:(导致带有曝光) Shader "Custom/doubleFaceTranspTexColor" { ...

  10. Phone

    User-Agent Switcher for Chrome EditThisCookie cornerstone SVN