題目: 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
文章標籤
全站熱搜
創作者介紹
創作者 低階ㄇㄋ 的頭像
低階ㄇㄋ

蟲匯聚之所

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