1、打乱数组
class Solution:
def __init__(self
, nums
):
self
.array
= nums
self
.original
= list(nums
)
def reset(self
):
self
.array
= self
.original
self
.original
= list(self
.original
)
return self
.array
def shuffle(self
):
for i
in range(len(self
.array
)):
swap_idx
= random
.randrange
(i
, len(self
.array
))
self
.array
[i
], self
.array
[swap_idx
] = self
.array
[swap_idx
], self
.array
[i
]
return self
.array
2、打乱栈
class MinStack(object):
def __init__(self
):
"""
initialize your data structure here.
"""
self
.items
= []
def push(self
, x
):
"""
:type x: int
:rtype: None
"""
self
.items
.append
(x
)
return None
def pop(self
):
"""
:rtype: None
"""
self
.items
.pop
()
return None
def top(self
):
"""
:rtype: int
"""
return self
.items
[len(self
.items
)-1]
def getMin(self
):
"""
:rtype: int
"""
return min(self
.items
)
转载请注明原文地址:https://tech.qufami.com/read-20248.html