Skip to content

Commit 181b00e

Browse files
Add files via upload
1 parent ba18e58 commit 181b00e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Happy Number/Happy_Number.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 第一种思路,简单粗暴,直接去模拟循环
2+
# 48ms 86.79%
3+
class Solution:
4+
def isHappy(self, n):
5+
"""
6+
:type n: int
7+
:rtype: bool
8+
"""
9+
res, numlist = 0, set()
10+
while res != 1:
11+
n = list(str(n))
12+
res = sum([int(item) ** 2 for item in n])
13+
if res in numlist:
14+
return False
15+
numlist.add(res)
16+
n = res
17+
return True

0 commit comments

Comments
 (0)