Happy Number
Examples
Example 1:
Input: n = 19
Output: true
Explanation:
Example 2:
Input: n = 2
Output: false
Example 1:
Input: n = 19
Output: true
Explanation:
Example 2:
Input: n = 2
Output: false
Write an algorithm to determine if a number n is happy.
A happy number is defined by the following process:
1 (where it will stay), or it loops endlessly in a cycle that does not include 1.Return true if n is a happy number, and false if not.
1^2 + 9^2 = 82, 8^2 + 2^2 = 68, 6^2 + 8^2 = 100, 1^2 + 0^2 + 0^2 = 1
1 <= n <= 2^31 - 1