import random
class Solution(object):
def __init__(self, nums):
"""
:type nums: List[int]
:type size: int
"""
self.nums = nums
def reset(self):
"""
Resets the array to its original configuration and return it.
:rtype: List[int]
"""
return self.nums
def shuffle(self):
"""
Returns a random shuffling of the array.
:rtype: List[int]
"""
ret = list(self.nums)
random.shuffle(ret)
return ret
Why do we use ret = list(self.nums)? I tried to use ret = left.nums, but it doesn't pass through the LeetCode solution. I don't understand why we put list() in front of self.nums. My guess is that self.nums is already a list.