일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- shiba
- kaggle
- 시바견
- Regular Expression
- 715. Range Module
- concurrency
- data science
- 밴픽
- Python Implementation
- Generator
- t1
- Decorator
- Python
- 컴퓨터의 구조
- 315. Count of Smaller Numbers After Self
- 109. Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- 파이썬
- Convert Sorted List to Binary Search Tree
- 운영체제
- 30. Substring with Concatenation of All Words
- LeetCode
- Class
- Python Code
- 프로그래머스
- iterator
- Protocol
- DWG
- attribute
Archives
- Today
- Total
Scribbling
LeetCode: 29. Divide Two Integers 본문
* Note: shift left is the same as multiplying by two.
class Solution:
def divide(self, dividend: int, divisor: int) -> int:
# Overflow
if dividend == -2**31 and divisor == -1:
return 2**31 - 1
# Positive?
positive = (dividend > 0) is (divisor > 0)
dividend = abs(dividend)
divisor = abs(divisor)
res = 0
subtract = divisor
while divisor <= dividend:
subtract, i = divisor, 1
while subtract <= dividend:
dividend -= subtract
res += i
i <<= 1
subtract <<= 1
if positive:
return res
return -res
'Computer Science > Coding Test' 카테고리의 다른 글
39. Combination Sum (0) | 2021.09.04 |
---|---|
32. Longest Valid Parentheses (0) | 2021.09.04 |
LeetCode: 50. Pow(x, n) (0) | 2021.09.02 |
LeetCode: 30. Substring with Concatenation of All Words (0) | 2021.08.29 |
LeetCode: 26. Remove Duplicates from Sorted Array (0) | 2021.08.27 |