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. 使用 Android 的日志工具LogCat

    Android 中的日志工具类是 Log(android.util.Log),这个类中提供了如下几个方法来供我们打印日志. 1.    Log.v() 这个方法用于打印那些最为琐碎的,意义最小的日志信 ...

  2. Spring Cloud Gateway服务网关

    原文:https://www.cnblogs.com/ityouknow/p/10141740.html Spring 官方最终还是按捺不住推出了自己的网关组件:Spring Cloud Gatewa ...

  3. ArcEngine二次开发错误编码对照表(转)

    阅读数:3323 每当我们在进行AE开发,出现错误时经常会出现错误代码,但是我们并不知道它到底代表什么意思,这里的而错误编码我们可以对照着找到我们需要的时候常详细信息(问题是,经常还是会出现没有错误编 ...

  4. 【jvm】java查看内存使用jmap,jstat和jstack使用 ,docker启动服务下查看jvm使用情况

    [声明,如果是docker启动的服务,可以在进入容器内后,再使用如下命令操作] [docker exec -it 容器ID  /bin/bash     即可进入容器内] [如果不是docker启动的 ...

  5. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

  6. 绝望的主妇第一二三季/Desperate Housewives迅雷下载

    绝望主妇 第一二三季 Desperate Housewives Season 1 2 3(2004 2005 2006) 本季看点:在紫藤街上住着这样一群主妇:拥有四个孩子和一个如孩子一般的丈夫的女强 ...

  7. Redis Nosql数据库

              Redis是一个key-value存储系统.和Memcached类似.可是攻克了断电后数据全然丢失的情况.并且她支持很多其它无化的value类型.除了和string外,还支持lis ...

  8. 利用ViewStub来延迟加载视图

    很多情况下,我们的视图可能会随着用户的操作的不同而变化,比如一个新的页面包含多个控件,但仅仅在用户点击这个按钮后,所有的控件才能完全显示.也就是说一上来可能就显示一个控件,点击按钮后把其他隐藏的控件再 ...

  9. 详细解读Android中的搜索框(四)—— Searchable配置文件

    <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android=" ...

  10. tf.transpose函数的用法讲解

    tf.transpose函数中文意思是转置,对于低维度的转置问题,很简单,不想讨论,直接转置就好(大家看下面文档,一看就懂). tf.transpose(a, perm=None, name='tra ...