two pointer
| 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 | |
| 42 | int main() { |
nothing calls this directly
no outgoing calls
no test coverage detected