We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f0792d1 commit 469e775Copy full SHA for 469e775
leetcode/0384.Shuffle-an-Array/384.Shuffle an Array.go
@@ -0,0 +1,28 @@
1
+package leetcode
2
+
3
+import "math/rand"
4
5
+type Solution struct {
6
+ nums []int
7
+}
8
9
+func Constructor(nums []int) Solution {
10
+ return Solution{
11
+ nums: nums,
12
+ }
13
14
15
+/** Resets the array to its original configuration and return it. */
16
+func (this *Solution) Reset() []int {
17
+ return this.nums
18
19
20
+/** Returns a random shuffling of the array. */
21
+func (this *Solution) Shuffle() []int {
22
+ arr := make([]int, len(this.nums))
23
+ copy(arr, this.nums)
24
+ rand.Shuffle(len(arr), func(i, j int) {
25
+ arr[i], arr[j] = arr[j], arr[i]
26
+ })
27
+ return arr
28
0 commit comments