Skip to content

Commit 469e775

Browse files
committed
add: leetcode 0384 solution
1 parent f0792d1 commit 469e775

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)