Problems / Happy Number
Easy

Happy Number

Easy 270 submissions 10 coins +50 XP
Hash Table Math
Problem Description
Repeatedly replace a positive integer by the sum of the squares of its digits. If the process reaches `1`, the number is *happy*; otherwise it loops forever. Return `true` if `n` is happy. **Example 1:** ``` Input: n = 19 Output: true ``` **Example 2:** ``` Input: n = 2 Output: false ``` **Example 3:** ``` Input: n = 1 Output: true ```
Constraints
- `1 <= n <= 2^31 - 1`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share