반응형
Complete the function that takes a non-negative integer n as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to n ( inclusive ).
Examples
n = 0 ==> [1] # [2^0]
n = 1 ==> [1, 2] # [2^0, 2^1]
n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2]
Solution:
def powers_of_two(n: str) -> list[int]:
return [pow(2, i) for i in range(n+1)]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0105. Greet Me (0) | 2023.01.05 |
---|---|
0104. Sleigh Authentication (0) | 2023.01.04 |
0102. Enumerable Magic #25 - Take the First N Elements (0) | 2023.01.03 |
0101. Pillars (0) | 2023.01.01 |
1231. For UFC Fans (Total Beginners): Conor McGregor vs George Saint Pierre (0) | 2022.12.31 |