Skip to content

Practice Happy Number

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#202
LeetCode Problem

Happy Number

Problem Statement

Starting with the positive integer n, repeatedly replace the current number with the sum of the squares of its decimal digits. A number is happy if this process reaches 1; otherwise it eventually repeats a cycle that excludes 1. Return true for a happy number and false otherwise.

Source: Happy Number on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 19
Output
true

# Example 2

Input
n = 2
Output
false

Constraints

1 <= n <= 2^31 - 1

Related LeetCode Problems

Practice more problems similar to Happy Number.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.