class Solution { public: bool isHappy(int n) { if(n <= 0) return false; set<int> res; while(res.count(n) == 0){ res.insert(n); int num = 0; while(n != 0){ num += (n%10)*(n%10); n = n/10; } if(num == 1) return true; n = num; } return false; } };
count()用来查找set中某个某个键值出现的次数
https://blog.csdn.net/lym940928/article/details/79671879