| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 시바견
- 30. Substring with Concatenation of All Words
- kaggle
- Python Code
- LeetCode
- 프로그래머스
- concurrency
- 파이썬
- iterator
- 컴퓨터의 구조
- shiba
- t1
- attribute
- 715. Range Module
- 43. Multiply Strings
- Python
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- DWG
- Python Implementation
- Protocol
- 315. Count of Smaller Numbers After Self
- Substring with Concatenation of All Words
- data science
- Decorator
- Generator
- 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 |