close

題目: 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].

解題想法: 直覺的就直接以一個for迴圈解題,同一迴圈中插入i與n+i兩個元素即可,或許可以找找其他效率更好的寫法

class Solution:
    def shuffle(self, nums: List[int], n: int) -> List[int]:
        k=[]
        for i in range(n):
            k.append(nums[i])
            k.append(nums[n+i])
        return k

arrow
arrow
    文章標籤
    leetcode python
    全站熱搜

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()