일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Substring with Concatenation of All Words
- Generator
- iterator
- Decorator
- 밴픽
- 43. Multiply Strings
- t1
- 715. Range Module
- attribute
- 컴퓨터의 구조
- 운영체제
- Regular Expression
- 30. Substring with Concatenation of All Words
- Protocol
- 파이썬
- DWG
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- Python Code
- data science
- 프로그래머스
- Class
- 시바견
- LeetCode
- Convert Sorted List to Binary Search Tree
- Python
- concurrency
- shiba
- 315. Count of Smaller Numbers After Self
- Python Implementation
Archives
- Today
- Total
Scribbling
LeetCode: 202. Happy Number 본문
class Solution:
def isHappy(self, n: int) -> bool:
def calc(x):
ret = 0
while x > 0:
ret += (x % 10)**2
x //= 10
return ret
numSet = set([n])
x = n
while True:
x = calc(x)
if x == 1:
return True
if x in numSet:
return False
numSet.add(x)
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 218. The Skyline Problem (0) | 2021.12.22 |
---|---|
LeetCode: 206. Reverse Linked List (0) | 2021.12.21 |
LeetCode: 191. Number of 1 Bits (0) | 2021.12.21 |
LeetCode: 171. Excel Sheet Column Number (0) | 2021.12.20 |
LeetCode: 125. Valid Palindrome (0) | 2021.12.20 |