Python one-line solution


  • 0
    A
    class Solution:
        def constructArray(self, n, k):
            """
            :type n: int
            :type k: int
            :rtype: List[int]
            """
            from functools import reduce 
            return list(reduce(lambda x, y: x + y, [[i, k+2-i] for i in range(1, (k+1) // 2 + 1)])) + ([] if k % 2 != 0 else [k // 2 + 1]) + list(range(k+2, n+1)) 
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.