# 202 Happy Number
15 算出 1² + 5² 可以先拆解成 15%10 + Math.floor(15/10)
write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits,
and repeat the process until the number equals 1 (where it will stay),
or it loops endlessly in a cycle which does not include 1.
Those numbers for which this process ends in 1 are happy numbers.Example:
Input: 19
Output: true
Explanation:
1² + 9² = 82
8² + 2² = 68
6² + 8² = 100
1² + 0² + 02 = 1
/**
* @param {number} n
* @return {boolean}
*/
var isHappy = function(n) {
};Edge Case
怎麼解
改善
學到什麼?
Last updated