class Solution {
public:
set<int>st;
bool isHappy(int n) {
while(n!=1){
vector<int>ans;
while(n>0){
int k=n%10;
if(k!=0)ans.push_back(k);
n=n/10;
}
n=0;
for(auto t:ans){
n+=t*t;
}
if(!st.count(n))st.insert(n);
else return false;
}
return true;
}
};
202. 快乐数
最新推荐文章于 2024-09-13 16:27:12 发布