Skip to content

Latest commit

 

History

History
27 lines (25 loc) · 576 Bytes

667.md

File metadata and controls

27 lines (25 loc) · 576 Bytes

667. Beautiful Arrangement II

Solution 1 (time O(n), space O(n))

class Solution(object):
    def constructArray(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: List[int]
        """
        ans = [0 for _ in range(n)]
        t = n - k - 1
        for i in range(t):
            ans[i] = i + 1
        i, a, b = t, n - k, n
        while i < n:
            ans[i] = a
            i += 1
            a += 1
            if i < n:
                ans[i] = b
                i += 1
                b -= 1
        return ans