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