MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / isHappy

Method isHappy

Two Pointers/202. Happy Number/Solution.cpp:28–39  ·  view source on GitHub ↗

two pointer

Source from the content-addressed store, hash-verified

26
27 // two pointer
28 bool isHappy(int n) {
29 if (n <= 0) return false;
30 int slow = next(n);
31 int fast = next(slow);
32 while (true) {
33 if (fast == slow) break;
34 slow = next(slow);
35 fast = next(next(fast));
36 if (fast == 1) return true;
37 }
38 return fast == 1 ? true : false;
39 }
40};
41
42int main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected