[LeetCode]#202. Happy Number

Input: 19
Output: true
Explanation:
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1
class Solution:
def Sum(self,num):
str_num=str(num)
res=0
for i in str_num:
res+=(int(i)**2)
return res


def isHappy(self, n: int) -> bool:
Table=[]
while n not in Table:
Table.append(n)
n=self.Sum(n)
if(n==1):
return True
break
if n in Table:
return False

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Top 10 Software Development Mistakes

PatternFly Elements theming hooks: CSS “Broadcast” Variables

What Can You Do With Python in 2021? (Python Real Life Applications)

Memory Layout

Power BI — Object Level Security

Journey to the IO Monad (Part 3.1)

J. A. Cirez, on the importance of being Ansible

J. A. Cirez, on the importance of being Ansible

Git Commands and Operations: Your Complete Guide

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

How to implement a stack class and deque. PYTHON data structures and algorithm.

[LeetCode]#2057. Smallest Index With Equal Value

Use of python dictionary get function

Data Structures Cookbook