class Solution { public: bool isHappy(int n) { map m; while (n != 1 && m.find(n) == m.end()) { m.insert(pair(n, 0)); int s = 0; while (n) { s += pow((n % 10), 2); n /= 10; } n = s; } if (n == 1) return true; else return false; } };