题目:

题解:
class Solution:
def __init__(self, w: List[int]):
self.pre = list(accumulate(w))
self.total = sum(w)
def pickIndex(self) -> int:
x = random.randint(1, self.total)
return bisect_left(self.pre, x)
题目:

题解:
class Solution:
def __init__(self, w: List[int]):
self.pre = list(accumulate(w))
self.total = sum(w)
def pickIndex(self) -> int:
x = random.randint(1, self.total)
return bisect_left(self.pre, x)
387

被折叠的 条评论
为什么被折叠?