class Solution {
public:
bool isHappy(int n) {
if(n==1)
return true;
while(n!=0)
{
res.insert(n);
vector<char> tmp;
while(n)
{
tmp.push_back(n%10);
n/=10;
}
for(int i=0;i<tmp.size();++i)
n += tmp[i]*tmp[i];
if(n==1)
return true;
if(res.find(n)!=res.end())
return false;
}
}
private:
set<int> res;
};
202 Happy Number
最新推荐文章于 2021-02-16 11:39:33 发布