Skip to content

Commit a8d935a

Browse files
committed
HappyNumber. 그러나 Hashset은 안쓰였다
1 parent 7e98b08 commit a8d935a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

python/basic/hashSet/happyNumber.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution(object):
2+
def isHappy(self, n):
3+
"""
4+
:type n: int
5+
:rtype: bool
6+
"""
7+
while(n != 1):
8+
if(n == 4):
9+
return False
10+
11+
strArr = list(str(n))
12+
n=0
13+
for s in strArr:
14+
nTemp = int(s)
15+
n += nTemp ** 2
16+
print(n)
17+
return True
18+
19+
20+
# num = 12345
21+
# print(list(str(num)))
22+
23+
s = Solution()
24+
print(s.isHappy(1221))
25+
print(s.isHappy(4))
26+
print(s.isHappy(7))
27+
print(s.isHappy(19))

0 commit comments

Comments
 (0)