일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- attribute
- iterator
- kaggle
- Protocol
- 운영체제
- data science
- 315. Count of Smaller Numbers After Self
- Substring with Concatenation of All Words
- 컴퓨터의 구조
- t1
- Python Code
- 프로그래머스
- Regular Expression
- 파이썬
- 밴픽
- LeetCode
- 109. Convert Sorted List to Binary Search Tree
- 시바견
- Decorator
- Python
- Python Implementation
- 43. Multiply Strings
- Generator
- 30. Substring with Concatenation of All Words
- shiba
- DWG
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- concurrency
- Class
Archives
- Today
- Total
Scribbling
LeetCode: 50. Pow(x, n) 본문
class Solution:
def myPow(self, x: float, n: int) -> float:
if n == 0:
return 1
if x == 1:
return 1
if x == -1:
if abs(n) % 2 == 0:
return 1
else:
return -1
if x == 0:
return 0
n_sign = True if n > 0 else False
res = 1
count = 0
while count < abs(n):
multiplier = x
step = 1
while step <= abs(n) - count:
res *= multiplier
count += step
step *= 2
multiplier *= multiplier
if n_sign:
return res
return 1 / res
'Computer Science > Coding Test' 카테고리의 다른 글
32. Longest Valid Parentheses (0) | 2021.09.04 |
---|---|
LeetCode: 29. Divide Two Integers (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 |
LeetCode: 24. Swap Nodes in Pairs (0) | 2021.08.26 |