Skip to content

Commit 99b17f7

Browse files
author
Parth Shah
authored
#202 Second Approach
1 parent af3a18a commit 99b17f7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

202_Happy_Number_1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def isHappy(self, n: int) -> bool:
3+
hmap = {}
4+
while n!=1:
5+
n = sum([pow(int(x),2) for x in str(n)])
6+
if n in hmap.keys():
7+
if hmap[n]:
8+
return False
9+
else:
10+
hmap[n] = 1
11+
return True

0 commit comments

Comments
 (0)