Happy number
Easymathhash setfast and slow pointers
Replace a number with the sum of the squares of its digits, and repeat. If it reaches 1 the number is happy; if it loops forever without reaching 1 it isn't. Return true if n is happy.
Example 1
Input: n = 19 Output: true
1² + 9² = 82 → 68 → 100 → 1.
Example 2
Input: n = 2 Output: false
Constraints
- 1 ≤ n ≤ 2³¹ - 1
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int} n
* @return {bool}
*/
function isHappy(n) {
}