1380. Lucky Numbers in a Matrix 链接到标题 给一个二维数组,分别求每行最小值,每列最大值,然后找到幸运数字。(遇到二维数组善用 zip 来解决
class Solution(object): def luckyNumbers (self, matrix): """ :type matrix: List[List[int]] :rtype: List[int] """ mins = {min(rows) for rows in matrix} maxes = {max(columns) for columns in zip(*matrix)} return list(mins & maxes) 1381. Design a Stack With Increment Operation 链接到标题 相比与 stack 多了一个 inc 操作,一般想法是每次遇到 inc 操作,那么我们遍历一次,将对应值进行加操作就可以了,但是这个操作是 O(n) 的,我们可以使用一个辅助 list ,保存 inc 的数值,当 pop 的时候,进行相加处理。
以示例展示处理过程:
["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"] [[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]] stack, inc [1], [0] [1,2], [0] [1], [0] [1,2], [0,0] [1,2,3], [0,0,0] [1,2,3], [0,0, 100] [1,2,3], [0, 100, 100] [1,2], [0,200] [1], [200] class CustomStack(object): def __init__(self, maxSize): self.