ByteByteGo logo
menuProblems List

Happy Number

Medium

In number theory, a happy number is defined as a number that, when repeatedly subjected to the process of squaring its digits and summing those squares, eventually leads to 1. An unhappy number will never reach 1 during this process, and will get stuck in an infinite loop.

Given an integer, determine if it's a happy number.

Example:

Input: n = 23
Output: True

Explanation: 222^2 + 323^2 = 13 ⇒ 121^2 + 323^2 = 10 ⇒ 121^2 + 020^2 = 1

You can practice coding exercises online by logging into bytebytego.com on your laptop.