123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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
- }
- func (this *Solution) Reset() []int {
- copy(this.sol, this.arr)
- return this.arr
- }
- 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
- }
|