MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / shuffle

Method shuffle

Java/shuffle-the-array.java:2–17  ·  view source on GitHub ↗
(int[] nums, int n)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[] shuffle(int[] nums, int n) {
3 int [] result = new int[2 * n];
4
5 // Looping over the array
6 for(int i = 0; i < 2 * n; i ++){
7 // If the array index is even
8 if(i % 2 == 0)
9 result[i] = nums[i / 2];
10
11 // If it's not even, its odd
12 else
13 result[i] = nums[n + i / 2];
14 }
15
16 return result;
17 }
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected