题解 | #快乐数#
https://www.nowcoder.com/practice/293b9ddd48444fa493dd17da0feb192d
/** * @param n int整型 * @return bool布尔型 */ function happynum( n ) { // 简单模拟 // write code here while (n > 9) { let sum = 0; while (n > 0) { let b = Math.floor(n % 10); // 注意 JS 取余要取整 sum += b * b; n /= 10; } n = sum; } if (n == 1) return true; return false; } module.exports = { happynum : happynum };