932. Beautiful Array
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 67% Topics: Array, Math, Divide and Conquer
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(n)
class Solution(object):
def beautifulArray(self, N):
"""
:type N: int
:rtype: List[int]
"""
result = [1]
while len(result) < N:
result = [i*2 - 1 for i in result] + [i*2 for i in result]
return [i for i in result if i <= N]
Solution from kamyu104/LeetCode-Solutions · MIT