Leetcode 202 Solution
This article provides solution to leetcode question 202 (happy-number)
Access this page by simply typing in "lcs 202" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/happy-number
Solution
class Solution {
public:
bool isHappy(int n) {
set<int> a;
while (a.find(n) == a.end())
{
a.insert(n);
int next = 0;
while (n)
{
next += (n % 10) * (n % 10);
n /= 10;
}
if (next == 1)
return true;
n = next;
}
return false;
}
};