1class Solution(object):2def __init__(self, w):3"""4:type w: List[int]5"""6# Cumulative sum7self.list = [0] * len(w)89s = 010for i, n in enumerate(w):11s += n12self.list[i] = s1314def pickIndex(self):15"""16:rtype: int17"""18return bisect_left(self.list, random.randint(1, self.list[-1]))192021# Your Solution object will be instantiated and called as such:22# obj = Solution(w)23# param_1 = obj.pickIndex()