Problem solving/Algorithms
[LeetCode] 1470. Shuffle the Array (Python)
Young_A
2021. 1. 10. 09:34
LeetCode - Problems - Algorithms - 1470. Shuffle the Array
Problem Description
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].
Example:
Constraints:
My Solution (Python)
class Solution:
def shuffle(self, nums, n):
answer = []
for x in range(n):
answer.append(nums[x]) # append x element
answer.append(nums[x+n]) # append y element
return answer