您的位置:首页 > 移动开发

[LeetCode]202. Happy Number

2017-04-29 23:00 267 查看

[LeetCode]202. Happy Number

题目描述



思路

没找到规律,只好用暴力做了

代码

#include <iostream>

using namespace std;

class Solution {
public:
bool isHappy(int n) {
while (n > 9) {
int next = 0;
while (n) {
next += (n % 10) * (n % 10);
n /= 10;
}
n = next;
}

return n == 1 || n == 7;
}
};

int main() {
Solution s;
cout << s.isHappy(19) << endl;

system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: