leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0202.cpp (355B)


0 class Solution { 1 public: 2 bool isHappy(int n) { 3 unordered_set<int> seen; 4 int tmp; 5 6 while (n != 1 && !seen.count(n)) { 7 seen.insert(n); 8 tmp = n, n = 0; 9 do { 10 n += (tmp % 10) * (tmp % 10); 11 } while ((tmp /= 10) > 0); 12 } 13 return !seen.count(n); 14 } 15 };