|
@@ -0,0 +1,57 @@
|
|
|
+//package main
|
|
|
+
|
|
|
+//import (
|
|
|
+// "fmt"
|
|
|
+// "math/rand"
|
|
|
+//)
|
|
|
+
|
|
|
+type Solution struct {
|
|
|
+ arr []int
|
|
|
+ sol []int
|
|
|
+}
|
|
|
+
|
|
|
+func Constructor(nums []int) Solution {
|
|
|
+ solution := Solution{arr: nums}
|
|
|
+ solution.sol = make([]int, len(nums))
|
|
|
+ copy(solution.sol, nums)
|
|
|
+ return solution
|
|
|
+}
|
|
|
+
|
|
|
+/** Resets the array to its original configuration and return it. */
|
|
|
+func (this *Solution) Reset() []int {
|
|
|
+ copy(this.sol, this.arr)
|
|
|
+ return this.arr
|
|
|
+}
|
|
|
+
|
|
|
+/** Returns a random shuffling of the array. */
|
|
|
+func (this *Solution) Shuffle() []int {
|
|
|
+ n := len(this.arr)
|
|
|
+ for i := 0; i < n; i++ {
|
|
|
+ j := i + rand.Intn(n-i)
|
|
|
+ this.sol[i], this.sol[j] = this.sol[j], this.sol[i]
|
|
|
+ }
|
|
|
+ return this.sol
|
|
|
+}
|
|
|
+
|
|
|
+//type tuple3 struct {
|
|
|
+// _1 int
|
|
|
+// _2 int
|
|
|
+// _3 int
|
|
|
+//}
|
|
|
+
|
|
|
+//func main() {
|
|
|
+// sol := Constructor([]int{1, 2, 3})
|
|
|
+// m := make(map[tuple3]int)
|
|
|
+// for i := 0; i < 10000; i++ {
|
|
|
+// arr := sol.Shuffle()
|
|
|
+// m[tuple3{arr[0], arr[1], arr[2]}]++
|
|
|
+// }
|
|
|
+// fmt.Println(m)
|
|
|
+//}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Your Solution object will be instantiated and called as such:
|
|
|
+ * obj := Constructor(nums);
|
|
|
+ * param_1 := obj.Reset();
|
|
|
+ * param_2 := obj.Shuffle();
|
|
|
+ */
|