일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 밴픽
- data science
- 운영체제
- Class
- 43. Multiply Strings
- 컴퓨터의 구조
- DWG
- kaggle
- attribute
- Convert Sorted List to Binary Search Tree
- Decorator
- iterator
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- Protocol
- 315. Count of Smaller Numbers After Self
- LeetCode
- Regular Expression
- Python Code
- concurrency
- 프로그래머스
- 시바견
- shiba
- 30. Substring with Concatenation of All Words
- Python
- Substring with Concatenation of All Words
- Generator
- 715. Range Module
- Python Implementation
- t1
Archives
- Today
- Total
Scribbling
LeetCode: 172. Factorial Trailing Zeroes 본문
알고리즘 문제라고 하기도 애매한 것 같다.
n! 결과값에서 맨 뒤에 놓이는 0의 갯수를 찾는 문제이다.
맨 뒤의 0의 갯수는 n!으로 만들 수 있는 10의 갯수와 동일한데,
10은 2*5이므로, 2*5가 몇 번 발생하는지 확인하면 된다.
2*5의 횟수는 다시 5의 횟수로 결정된다. (2는 흔하니까)
class Solution:
def trailingZeroes(self, n: int) -> int:
ret = 0
x = 5
while n >= x:
ret += n // x
x *= 5
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 198. House Robber (0) | 2021.12.04 |
---|---|
LeetCode: 179. Largest Number (0) | 2021.12.04 |
LeetCode: 160. Intersection of Two Linked Lists (0) | 2021.12.02 |
LeetCode: 162. Find Peak Element (0) | 2021.12.01 |
LeetCode: 155. Min Stack (0) | 2021.11.30 |