LintCode: Happy Number
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的更多相关文章
- Lintcode: Majority Number III
Given an array of integers and a number k, the majority number is the number that occurs more than 1 ...
- Lintcode: Majority Number II 解题报告
Majority Number II 原题链接: http://lintcode.com/en/problem/majority-number-ii/# Given an array of integ ...
- Lintcode: Majority Number 解题报告
Majority Number 原题链接:http://lintcode.com/en/problem/majority-number/# Given an array of integers, th ...
- [LintCode] Majority Number 求众数
Given an array of integers, the majority number is the number that occurs more than half of the size ...
- [LintCode] Single Number 单独的数字
Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...
- [LintCode] Valid Number 验证数字
Validate if a given string is numeric. Have you met this question in a real interview? Yes Example & ...
- [LintCode] Happy Number 快乐数
Write an algorithm to determine if a number is happy. A happy number is a number defined by the foll ...
- [LintCode] Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number`. Ugly numbers are positive number ...
- Lintcode: Majority Number II
Given an array of integers, the majority number is the number that occurs more than 1/3 of the size ...
- lintcode:Ugly Number I
Ugly Number Write a program to check whether a given number is an ugly number`. Ugly numbers are pos ...
随机推荐
- ASP.NET Web API基于OData的增删改查,以及处理实体间关系
本篇体验实现ASP.NET Web API基于OData的增删改查,以及处理实体间的关系. 首先是比较典型的一对多关系,Supplier和Product. public class Product { ...
- DirectX - dds图片格式(DDSURFACEDESC2)
DDS是DirectDraw Surface的缩写,它是DirectX纹理压缩(DirectX Texture Compression,简称DXTC)的产物. DXTC减少了纹理内存消耗的50%甚至更 ...
- 安装/使用 MVVMLight(转)
安装 MVVMLight Toolkit 为什么说是 MVVMLight Toolkit ?实际上我们一般安装的都是 MVVMLight Toolkit ,这个里面包含了工具就是在VS新建工程的时候你 ...
- Windows Phone本地数据库(SQLCE):3、[table]attribute(翻译) (转)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第三篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...
- log4j直接输出日志到flume
log4j.properties配置: log4j.rootLogger=INFOlog4j.category.com.besttone=INFO,flumelog4j.appender.flume ...
- iPhone/iPad各种文件路径详解 帮助了解自己的iphone和ipad
以下内容皆为转载分享iPhone里重要的目录路径有哪几个? 1. /private/var/mobile 新刷完的机器,要在这个文件夹下建一个Documents的目录,很多程序都要用到. 2. /pr ...
- C#编程(六十一)------------LINQ中的扩展方法
原文链接: http://blog.csdn.net/shanyongxu/article/details/47208401 LINQ中的扩展方法 LINQ中where扩展方法,要想使用,必须导入us ...
- 电脑不能使用ArcMap 提示由于系统时间不对造成的怎么办?转
来自:http://www.jb51.net/diannaojichu/334554.html 电脑不能使用ArcMap,在打开ARCMAP时,出现"The system clock has ...
- 解决Oracle EM 乱码问题
原创 作者:fa042 时间:2012-11-17 16:50:34 199 0 Oracle 10g提供了一个基于Web的管理工具EM(Enterprise Manager),使用比较方便.不过,如 ...
- “finally block does not complete normally”的警告解决
但是,java里面不是可以保证finally一定会执行的么,为什么不可以在finally块做return??? 细细看道来: debug一下这个函数,就会惊讶的发现, 里面抛出的异常会被finally ...