Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Solution to Leetcode-Easy #1470 - Shuffle The Array #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions leetcode/easy/Arrays and Strings/ShuffleTheArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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].

#Input: nums = [2,5,1,3,4,7], n = 3
#Output: [2,3,5,4,1,7]
#Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7]

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