C++
1 class Solution {
2 public:
3 /**
4 * @param n an integer
5 * @return true if this is a happy number or false
6 */
7 bool isHappy(
int n) {
8 // Write your code here
9 int a, b;
10 if (n <=
0)
return false;
11 if (n <
10) n = n*
n;
12 while (n >
9) {
13 a =
0;
14 while (n) {
15 b = n%
10;
16 a += b*
b;
17 n /=
10;
18 }
19 n =
a;
20 }
21 return n ==
1;
22 }
23 };
转载于:https://www.cnblogs.com/CheeseZH/p/5105353.html
相关资源:数据结构—成绩单生成器
转载请注明原文地址: https://win8.8miu.com/read-1494848.html