C++

 class Solution {
public:
/**
* @param n an integer
* @return true if this is a happy number or false
*/
bool isHappy(int n) {
// Write your code here
int a, b;
if (n <= ) return false;
if (n < ) n = n*n;
while (n > ) {
a = ;
while (n) {
b = n%;
a += b*b;
n /= ;
}
n = a;
}
return n == ;
}
};

LintCode: Happy Number的更多相关文章

  1. Lintcode: Majority Number III

    Given an array of integers and a number k, the majority number is the number that occurs more than 1 ...

  2. Lintcode: Majority Number II 解题报告

    Majority Number II 原题链接: http://lintcode.com/en/problem/majority-number-ii/# Given an array of integ ...

  3. Lintcode: Majority Number 解题报告

    Majority Number 原题链接:http://lintcode.com/en/problem/majority-number/# Given an array of integers, th ...

  4. [LintCode] Majority Number 求众数

    Given an array of integers, the majority number is the number that occurs more than half of the size ...

  5. [LintCode] Single Number 单独的数字

    Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...

  6. [LintCode] Valid Number 验证数字

    Validate if a given string is numeric. Have you met this question in a real interview? Yes Example & ...

  7. [LintCode] Happy Number 快乐数

    Write an algorithm to determine if a number is happy. A happy number is a number defined by the foll ...

  8. [LintCode] Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number`. Ugly numbers are positive number ...

  9. Lintcode: Majority Number II

    Given an array of integers, the majority number is the number that occurs more than 1/3 of the size ...

  10. lintcode:Ugly Number I

    Ugly Number Write a program to check whether a given number is an ugly number`. Ugly numbers are pos ...

随机推荐

  1. 在busybox里使用ulimit命令

    刚才想使用ulimit修改用户进程的用户栈的大小,发现busybox里没有这个命令,上google搜索得到如下解释: "ulimit" is a shell builtin, me ...

  2. ES6的一些基本用法

    ● let ● variable hoisting ● arrow Function, Lambda表达式 ● Destructuring Assignments 解构赋值 ● 默认参数值 Defau ...

  3. Xcode 统计项目代码行数及常用快捷键

    1.统计Xcode项目代码行数 1   打开终端. 2  用ls和cd进到你项目的路径. 3   输入下面的指令: grep -r "\n" classes | wc -l (cl ...

  4. ExtJS动态设置表头

    if(document.getElementById("lxdj_radio").checked){ colQd = new Ext.grid.ColumnModel(colMAr ...

  5. 【Devops】【docker】【CI/CD】2.docker启动jenkins环境+安装必要的插件

    [注意:]jenkins的docker镜像,需要从官网进入直接获取,其他地方获取到的docker镜像,可能因为Jenkins版本过低,导致后续插件安装失败等问题!!! ================ ...

  6. Mac上 python 找不到 yaml模块

    (1)  yaml http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion 1.报错 ImportError: N ...

  7. [Android Security] 反编译常用工具

    copy : https://down.52pojie.cn/Tools/Disassemblers/

  8. EndNote在Word中插入文献不能自动生成编号 - 解决方案

    本文出处:新浪博客“小数码植物摄影”之http://blog.sina.com.cn/s/blog_629be3eb0100sih3.html 新浪博客“小数码植物摄影”首页:http://blog. ...

  9. 【转】windows下mongodb安装与使用整理

    转自 :http://www.cnblogs.com/lecaf/archive/2013/08/23/mongodb.html 一.首先安装mongodb 1.下载地址:http://www.mon ...

  10. python模块uuid产生唯一id

    使用版本4:uuid4就可以了 UUID4缺点:糟糕的随机数发生器使得它更有可能发生碰撞,但是概率真的很小 UUID1缺点:暴露隐私 If all you want is a unique ID, y ...