Peeush Agarwal > Engineer. Learner. Builder.

I am a Machine Learning Engineer passionate about creating practical AI solutions using Machine Learning, NLP, Computer Vision, and Azure technologies. This space is where I document my projects, experiments, and insights as I grow in the world of data science.

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