Notes

Personal notes on various topics

View on GitHub

Happy Number

Problem Statement

Given a positive integer n, determine if it is a happy number.

A happy number is defined by the following process:

Return true if n is a happy number, otherwise return false.

Examples

Example 1:

Input: n = 19
Output: true
Explanation:
1² + 9² = 82
8² + 2² = 68
6² + 8² = 100
1² + 0² + 0² = 1

Example 2:

Input: n = 2
Output: false

Constraints

Code Template

class Solution:
    def isHappy(self, n: int) -> bool:
        # Your code here
        pass

Solutions

Back to Problem List Back to Categories