1.数组leetcode
class SubrectangleQueries:
def __init__(self, rectangle: List[List[int]]):
self.data = rectangle
self.update = []
def updateSubrectangle(self, row1: int, col1: int, row2: int, col2: int, newValue: int) -> None:
self.update.append((row1, col1, row2, col2, newValue))
def getValue(self, row: int, col: int) -> int:
res = None
for i in range(len(self.update)-1, -1, -1):
row1,col1,row2,col2, val = self.update[i]
if row1 <= row <= row2 and col1<= col <= col2:
res = val
break
return res if res else self.data[row][col]
知识点
1.py中二维数组怎么存取:
2.把更新信息储存到一个集合里,选择什么集合呢?列表?元祖?集合?
3.range(, ,-1)函数反向取值的逻辑
4.return if else
作者:JamLeon
链接:https://leetcode-cn.com/problems/subrectangle-queries/solution/shuang-100jie-ti-si-lu-bing-li-yong-pythonte-xing-/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。