Skip to content

Commit 502bf16

Browse files
committed
Time: 56 ms (71.26%), Space: 17.8 MB (98.22%) - LeetHub
1 parent 342075f commit 502bf16

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def shuffle(self, nums: List[int], n: int) -> List[int]:
8+
result = []
9+
for i in range(n):
10+
result.append(nums[i])
11+
result.append(nums[n+i])
12+
return result
13+
14+
15+
nums = [2, 5, 1, 3, 4, 7]
16+
n = 3
17+
print(Solution().shuffle(nums, n))
18+
nums = [1, 2, 3, 4, 4, 3, 2, 1]
19+
n = 4
20+
print(Solution().shuffle(nums, n))
21+
nums = [1, 1, 2, 2]
22+
n = 2
23+
print(Solution().shuffle(nums, n))

0 commit comments

Comments
 (0)