leetcode刷题:304. 二维区域和检索 - 矩阵不可变

in STEEM CN/中文2 years ago

题目:

image.png

今天这题目算是昨天303的威力加强版,思路是按昨天的来,先计算好每个数组各种排列的索引元素的和,然后再稍微一减。最后把和相加。

代码如下:

class NumMatrix:
    def __init__(self, matrix: List[List[int]]):
        self.num_sum = []
        for i in matrix:
            cache=[0]
            for t in range(len(i)):
                cache.append(cache[t]+i[t])
            self.num_sum.append(cache)      
    def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:
        re=0
        if row2-row1 >0:
            for i in range(row2-row1+1):
                re += self.num_sum[row1+i][col2+1]-self.num_sum[row1+i][col1]
        else:
            re = self.num_sum[row1][col2+1]-self.num_sum[row1][col1]
        return re

image.png

速度有点慢,我想想怎么改进

Sort:  

拍拍

 2 years ago 

请教问题:我想投票nutbox作为见证人,为什么老是提示 Oops, something went wrong. Here is the error message:
"voter.proxy.size() == 0: A proxy is currently set, please clear the proxy before voting for a witness." ,

是因为uses maiyude as a voting proxy?

Coin Marketplace

STEEM 0.22
TRX 0.06
JST 0.025
BTC 19410.71
ETH 1335.02
USDT 1.00
SBD 2.47