MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / isHappy

Function isHappy

javascript/0202-happy-number.js:8–17  ·  view source on GitHub ↗
(n, seen = new Set())

Source from the content-addressed store, hash-verified

6 * @return {boolean}
7 */
8var isHappy = (n, seen = new Set()) => {
9 const hasCycle = () => n === 1 || seen.has(n);
10 while (!hasCycle()) {
11 /* Time O(log(N)) */
12 seen.add(n); /* Space O(log(N)) */
13 n = getNext(n); /* Time O(log(N)) */
14 }
15
16 return n === 1;
17};
18
19var getNext = (n, sum = 0) => {
20 while (0 < n) {

Callers

nothing calls this directly

Calls 4

getNextFunction · 0.85
hasCyleFunction · 0.85
hasCycleFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected