Posted on 2023-02-07 18:29
Uriel 阅读(30)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
将一个排序为[x1, x2,..., xn, y1, y2,..., yn]重新排序为[x1, y1,..., xn, yn]输出
可以有O(1)空间的写法,但是偷懒直接写了O(n)的
1 #1470
2 #Runtime: 44 ms (Beats 62.31%)
3 #Memory: 13.5 MB (Beats 92.33%)
4
5 class Solution(object):
6 def shuffle(self, nums, n):
7 """
8 :type nums: List[int]
9 :type n: int
10 :rtype: List[int]
11 """
12 ans = [0] * 2 * n
13 for i in range(n):
14 ans[2 * i] = nums[i]
15 for i in range(n):
16 ans[2 * i + 1] = nums[i + n]
17 return ans