Leetcode: Happy Number
# Happy Number Checker
# What is a Happy Number?
In number theory, a b-happy number is a natural number in a given number base b that eventually reaches 1 when iterated over the perfect digital invariant function for p=2. Those numbers that do not end in 1 are b-unhappy numbers (or b-sad numbers).
For instance, the number 19 is a happy number because
# However, 20 is not happy number
... and it won't stop
# Programming
This is tricky because if a number is not happy number, the checker would be running forever and won't stop. In this case, I just think the number be happy number if we compute over 1000 times and the answer is still not equal to zero.
Due to we want to get the square of each bit, so we could use operator %
to handle this.
# REFERENCES
Updated: 2021/09/05, 15:42:35