mycode

关键不知道怎么退出循环。。。。。。。。。。。。。其实只要有一个平方和以前出现过,那么整个计算过程就会重复

参考:

class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
""" mem=set() while n!=1:
new_n=0
while n:
new_n+=(n%10)**2
n/=10
if new_n in mem: return False
mem.add(new_n)
n=new_n return True

leetcode-mid-math-202. Happy Number-NO的更多相关文章

  1. [LeetCode&Python] Problem 202. Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  2. Leetcode 202 Happy Number 弗洛伊德判环解循环

    今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表 ...

  3. LeetCode 287. Find the Duplicate Number (python 判断环,时间复杂度O(n))

    LeetCode 287. Find the Duplicate Number 暴力解法 时间 O(nlog(n)),空间O(n),按题目中Note"只用O(1)的空间",照理是过 ...

  4. [LeetCode] 202. Happy Number 快乐数

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  5. LeetCode 202. Happy Number (快乐数字)

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  6. 【一天一道LeetCode】#202. Happy Number

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  7. 【LeetCode】 202. Happy Number 解题报告(Java & Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:h ...

  8. LeetCode 202 Happy Number

    Problem: Write an algorithm to determine if a number is "happy". A happy number is a numbe ...

  9. Java for LeetCode 202 Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  10. (easy)LeetCode 202.Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

随机推荐

  1. 剑指offer-递归和循环-python

    -斐波那契数列- 大家都知道斐波那契数列(1.1.2.3.5.8.13.21.34.……),现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). n<=39 斐波那契数 ...

  2. wex5 如何写后台BAAS

    Data.java: 在class中链接数据源: 配置的numsql数据源 private static final String DATASOURCE_NUMYSQL = "numysql ...

  3. 关于mysql varchar(N)

    varchar(N) 能存多少个中文字符? 4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个中文3字节) gbk :每个字符最多占用2个字节 utf8 ...

  4. Struts2.5以上版本There is no Action mapped for namespace [/] and action name [userAction_login] associated with context path []

    分析:Struts2在2.5版本后添加strict-method-invocation(严格方法访问),默认为true,不能使用动态方法调用功能,故需设为false struts.xml设置如下: & ...

  5. IDEA debug模式鼠标悬停提示变量值

  6. 2019-11-29-dotnet-文件读写务必注意事项

    title author date CreateTime categories dotnet 文件读写务必注意事项 lindexi 2019-11-29 08:34:43 +0800 2019-10- ...

  7. 关于AP如何获取station的rssi

    最近在研究一个问题:如何通过AP来获取station的rssi. 具体可以拆分为以下三种情况: 1.首先station如果已经连接到AP上,这种情况很容易就能够得到station的RSSI.这里就不讨 ...

  8. 用Maven搭建简单的SpringMVC框架

    本文会详细阐述如何用Maven搭建一个简单的SpringMVC框架 这里就不介绍SpringMVC框架了,咱们直接来搭建 第一步 创建一个Maven的web项目  这里有一个简单的方法 new一个Ma ...

  9. 跨域 (1) jsonp 跨域

    jsonp 的例子 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  10. 【HDU4003】Find Metal Mineral

    题目大意:给定一棵 N 个节点的有根树,边有边权,在根结点处有 K 个人,这些人会遍历树上的所有边,求如何遍历才能使得所有人走过路径的边权和最小. 题解: 引理:对于一棵子树来说,若存在 M>0 ...