Skip to content

Commit 2b375b0

Browse files
Update Happy_Number.js (ignacio-chiazzo#93)
2 parents 21e198d + 9e1d57d commit 2b375b0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

LeetcodeProblems/Algorithms/easy/Happy_Number.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ Example 2:
2525
Input: n = 2
2626
Output: false
2727
28+
Example 3:
29+
Input n = 7
30+
Output = true
31+
Explanation:
32+
7^2 = 49
33+
4^2 + 9^2 = 97
34+
9^2 + 7^2 = 130
35+
1^2 + 3^2 + 0^2 = 10
36+
1^2 + 0^2 = 1
2837
2938
*/
3039

@@ -40,7 +49,7 @@ function checkHappyNumber(n){
4049
let strNumber = n.toString();
4150
let splitNumber = strNumber.split("");
4251
if(splitNumber.length <= 1){
43-
return (n <= 1)? true:false;
52+
return (n === 1 || n === 7)? true:false;
4453
}
4554
const digit = splitNumber.reduce((a,b)=> parseInt(a) + Math.pow(parseInt(b),2),0);
4655
return checkHappyNumber(digit);

0 commit comments

Comments
 (0)