我的算法之路19-- Shuffle an Array

class Solution:

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

    def reset(self) -> List[int]:
        """
        Resets the array to its original configuration and return it.
        """
        return self.nums

    def shuffle(self) -> List[int]:
        """
        Returns a random shuffling of the array.
        """
        nm=self.nums[:]
        for i in range(len(nm)-1,-1,-1):
            j=random.randint(0,i)
            nm[i],nm[j]=nm[j],nm[i]
        return nm
 

猜你喜欢

转载自blog.csdn.net/joaming/article/details/89476781