1
import random
2

3

4
class Solution:
5

6
def __init__(self, nums: List[int]):
7
self.nums = nums
8

9
def reset(self) -> List[int]:
10
return self.nums
11

12
def shuffle(self) -> List[int]:
13
shuffled_array = self.nums.copy()
14
# randomly generates the idx of the element that'll be the ith element of the array
15
for i in range(len(self.nums) - 1, 0, -1):
16
idx = random.randint(0, i)
17
shuffled_array[i], shuffled_array[idx] = (
18
shuffled_array[idx],
19
shuffled_array[i],
20
)
21
return shuffled_array

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0