Skip to content

Commit 599e3b2

Browse files
committed
Update
1 parent ecb03de commit 599e3b2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

algorithms/happy-number.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @return {boolean}
44
*/
55
var isHappy = function (n) {
6-
// 用哈希集合检测循环
7-
86
// 获取下一个数
97
const getNext = (num) => {
108
let sum = 0;
@@ -15,7 +13,10 @@ var isHappy = function (n) {
1513
}
1614
return sum;
1715
};
16+
17+
// 用哈希集合检测循环
1818
const set = new Set();
19+
1920
while (n !== 1 && !set.has(n)) {
2021
set.add(n);
2122
n = getNext(n);

0 commit comments

Comments
 (0)