1470. Shuffle the Array

Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].

Return the array in the form [x1,y1,x2,y2,...,xn,yn].

class Solution(object):
    def shuffle(self, nums, n):
        """
        :type nums: List[int]
        :type n: int
        :rtype: List[int]
        """
        i = 0
        j = n
        ans = []
        while i < n:
            ans.append(nums[i])
            ans.append(nums[j])
            i += 1
            j += 1
        return ans
        

 

posted @ 2020-06-28 21:08  whatyouthink  阅读(92)  评论(0编辑  收藏  举报