预计再过半个月就可以写项目了,不知道像我这样的彩笔,能不能驾驭得住项目难度,希望可以随便拿捏。
class Solution {
public:
bool isHappy(int n) {
unordered_set<int> unset;
while(1){
int sum = getNextNum(n);
if(sum == 1) return true;
if(unset.find(sum) != unset.end()){
return false;
}else{
unset.insert(sum);
}
n = sum;
}
}
private:
int getNextNum(int n){
int ret = 0;
while(n != 0){
int temp = n % 10;
ret += pow(temp, 2);
n /= 10;
}
return ret;
}
};
标签:10,202,return,int,sum,ret,快乐,unset From: https://www.cnblogs.com/llllmz/p/18449386