Skip to content

Commit

Permalink
Add 1470-shuffle-the-array
Browse files Browse the repository at this point in the history
  • Loading branch information
AkifhanIlgaz committed Feb 6, 2023
1 parent 07e1146 commit fa7a99d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions go/1470-shuffle-the-array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "math"

func main() {

}

func shuffle(nums []int, n int) []int {
for i := 0; i < n; i++ {
nums[i] = nums[i] << 10
nums[i] = nums[i] | nums[i+n]
}

j := 2*n - 1

for i := n - 1; i > -1; i-- {
y := nums[i] & (int(math.Pow(2.,10.)) - 1)
x := nums[i] >> 10
nums[j] = y
nums[j-1] = x
j -= 2
}
return nums
}
23 changes: 23 additions & 0 deletions javascript/1470-shuffle-the-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param {number[]} nums
* @param {number} n
* @return {number[]}
*/
var shuffle = function (nums, n) {
for (let i = 0; i < n; i++) {
nums[i] = nums[i] << 10;
nums[i] = nums[i] | nums[i + n];
}

let j = 2 * n - 1;

for (let i = n - 1; i > -1; i--) {
let y = nums[i] & (2 ** 10 - 1);
let x = nums[i] >> 10;
nums[j] = y;
nums[j - 1] = x;
j -= 2;
}

return nums;
};
18 changes: 18 additions & 0 deletions typescript/1470-shuffle-the-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function shuffle(nums: number[], n: number): number[] {
for (let i = 0; i < n; i++) {
nums[i] = nums[i] << 10;
nums[i] = nums[i] | nums[i + n];
}

let j = 2 * n - 1;

for (let i = n - 1; i > -1; i--) {
let y = nums[i] & (2 ** 10 - 1);
let x = nums[i] >> 10;
nums[j] = y;
nums[j - 1] = x;
j -= 2;
}

return nums;
}

0 comments on commit fa7a99d

Please sign in to comment.