LeetCode304. Range Sum Query 2D - Immutable

银河麒麟系统V10 sp1,安装wine 9.0 银河麒麟系统V10 sp1 x86_64,安装wine 9.0 阅读详情
题目链接:

https://leetcode.com/problems/range-sum-query-2d-immutable/

题目描述:

求矩阵数组中由左上角点(row1,col1)和右下角点(row2,col2)形成的矩形中所有数字之和。

题目分析:

动态规划的思想。

sums[i][j]=sums[i-1][j]+sums[i][j-1]-sums[i-1][j-1]+matrix[i][j];
代码:
class NumMatrix {
public:
    NumMatrix(vector<vector<int>> &matrix) {
        int row=matrix.size();
        if(row==0){
            return;
        }
        int col=matrix[0].size();
        sums=vector<vector<int>>(row,vector<int>(col,0));
        sums[0][0]=matrix[0][0];
        for(int i=1;i<row;i++){
            sums[i][0]=sums[i-1][0]+matrix[i][0];
        }
        for(int i=1;i<col;i++){
            sums[0][i]=sums[0][i-1]+matrix[0][i];
        }
        for(int i=1;i<row;i++){
            for(int j=1;j<col;j++){
                sums[i][j]=sums[i-1][j]+sums[i][j-1]-sums[i-1][j-1]+matrix[i][j];
            }
        }
    }

    int sumRegion(int row1, int col1, int row2, int col2) {
        if(row1>row2 || col1>col2){
            return 0;
        }
        if(row1==0 && col1==0){
            return sums[row2][col2];
        }
        else if(row1==0){
            return sums[row2][col2]-sums[row2][col1-1];
        }
        else if(col1==0){
            return sums[row2][col2]-sums[row1-1][col2];
        }
        else{
            return sums[row2][col2]-sums[row2][col1-1]-sums[row1-1][col2]+sums[row1-1][col1-1];
        }
    }
private:
    vector<vector<int>> sums;
};
YoloV10改进策略:卷积篇|基于PConv的二次创新|附结构图|性能和精度得到大幅度提高(独家原创) 在PConv的基础上做了二次创新,创新后的模型不仅在精度和速度上有了质的提升,还可以支持Stride为2的降采样。改进方法简单高效,需要发论文的同学不要错过! 阅读详情

相关推荐

iPhone免越狱Git服务器搭建教程-iSH

iPhone免越狱Git服务器搭建教程

jts666的博客 4427

LeetCode //C - 304. Range Sum Query 2D - Immutable

【代码】LeetCode //C - 304. Range Sum Query 2D - Immutable。

Made in Code 1356

stm32驱动NRF24L01_原理+代码解析

NRF24L01是NORDIC公司生产的一款无线通信通信芯片,采用FSK 调制,集成NORDIC自家的Enhanced Short Burst协议。可以实现点对点或是1对6的无线通信。无线通信速度最高可达到2Mbps。①2.4G全球开放的ISM频段,免许可证使用。②最高工作速率2Mbps,高校的GFSK调制,抗干扰能力强。③126个可选的频道,满足多点通信和调频通信的需要。④内置CRC检错和点对多点的通信地址控制。⑤可设置自动应答,确保数据可靠传输。//NRF24L01寄存器操作命令。

zyc18700766982的博客 2万+

【Leetcode】304. Range Sum Query 2D - Immutable

要求设计一个数据结构,可以实现查询左上从。查询的时候,利用前缀和做差即可。范围内矩阵数字的和的操作。列的所有数字的和,规定。

数学、算法爱好者的博客 224

宜搭,高级认证实操2,FaaS连接器指导教程

找到FaasEntry.java将如下代码整体替换,注意引包。如图所示在util下新建EDSUtil.java代码如下。回到连接器界面点击右上角测试-->测试。连接器工厂-->新建FaaS连接器。保存-->前往云IDE开发。返回如图所示代码,部署成功。

2301_80286061的博客 3342

RS422总线

①.RS422发送驱动器无高阻三态(浮空)状态RS422收发芯片,发送脚固定强驱动输出,永远钳位 A/B 差分电平,不能关断、不能悬空,只要芯片上电,TX+、TX - 就强制输出互补电压(一路高、一路低)。多条发送并联在同一组差分线上:两个驱动器一个拉 A 高、一个拉 A 低,B 线反向拉扯 → 电源→地大电流对灌,瞬间芯片过流发烫烧毁、总线电平短路错乱。注意:RS485 带DE/RE 收发使能脚:不用发送时可关闭驱动器,输出变成高阻浮空,让出总线,因此能多节点分时发送。③.多点通信方式,一主多从方式;

zhuimeng_1234的博客 222

LeetCode(304)Range Sum Query 2D - Immutable

题目Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). Range Sum Query 2D The above rectang

指尖飞舞 2802

QCM6490平台DDR测试:从QDUTT配置到眼图分析的实战指南

本文详细介绍了QCM6490平台DDR测试的全流程,从QDUTT工具安装配置到眼图分析,提供了实战操作指南和常见问题解决方案。通过具体案例分享,帮助工程师掌握DDR测试技巧,确保内存稳定性,特别适用于物联网和边缘计算设备的开发调试。

weixin_33910191的博客 457

[leetcode-304]Range Sum Query 2D - Immutable

[leetcode-304]Range Sum Query 2D - Immutable

100120101的博客 1698

实验5 振幅调制(集成乘法器幅度调制电路)

目录5-1 振荡调制的基本工作原理一.振幅调制和调幅波1.普通调幅波(AM)(1)调幅波的表达式、波形(2)调幅波的频谱2.抑制载波双边带调幅(DSB)3.抑制载波单边带调幅(SSB)二.普通调幅波的产生电路三.抑制载波调幅的产生电路5-2 振幅调制实验电路 5-1 振荡调制的基本工作原理 根据电磁波理论知道,只有频率较高的振荡才能被天线有效地辐射。但是人的讲话声音变换为相应电信号的频率较低,不适于直接从天线上辐射。因此,为了传递信息,就必须将要传递的信息“记载”到高频振荡上去。这一“记载”过程称为调

胡毛毛的博客 3万+

一桶令牌的时间账本:四类限流算法的边界推演与Guava RateLimiter源码精读

限流的难点不在背出算法名,而在算清每一笔账:按哪一秒计数、超额请求排队还是拒绝、空闲后能否突发、集群总量如何约束。本文在可复现的虚拟时间实验台上对比固定窗口、滑动窗口、漏桶与令牌桶,实测边界双倍突发与分桶滑动的真实上界,拆解Nginx limit_req的千分位记账与延迟机制,纠正Resilience4j常被误称漏桶的说法,并逐行精读Guava SmoothRateLimiter的预消费、懒惰补账与预热积分,复刻迷你限流器与其完成七万次零差异对账,最后给出集群配额、分层防护与参数确定的方法。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 86万+

[leetcode] 304. Range Sum Query 2D - Immutable 解题报告

题目链接:https://leetcode.com/problems/range-sum-query-2d-immutable/ Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lowe

小榕流光的专栏 794

汽车行业OTD业务模式入门学习

本文是在学习彭俊松老师的《汽车行业整车订单交付系统》后,对于OTD理解的一些摘录,供诸位参考学习。

qq_40664711的博客 1万+

LeetCode-304. Range Sum Query 2D - Immutable & 307. Range Sum Query - Mutable

303. Range Sum Query - Immutable class NumArray { int[] accum; public NumArray(int[] nums) { accum=new int[nums.length+1]; for(int i=1;i<=nums.length;i++)...

To_be_thinking的博客 201

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[LeetCode] 304. Range Sum Query 2D - Immutable

原题链接: https://leetcode.com/problems/range-sum-query-2d-immutable/ 1. 题目介绍 Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and ...

Ber03的博客 203

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LeetCode 304. Range Sum Query 2D - Immutable

分析 难度 中 来源 https://leetcode.com/problems/range-sum-query-2d-immutable/ 题目 Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and ...

ov流岚vo的专栏 313

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

LeetCode: 304. Range Sum Query 2D - Immutable

LeetCode: 304. Range Sum Query 2D - Immutable 题目描述 Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row...

杨领well的专栏 184

LeetCode-304. Range Sum Query 2D - Immutable [C++][Java]

Calculate thesumof the elements ofmatrixinside the rectangle defined by itsupper left corner(row1, col1)andlower right corner(row2, col2).

贫道绝缘子的博客 232

LeetCode 304. Range Sum Query 2D - Immutable (Java版; Medium)

welcome to my blog LeetCode Top 100 Liked Questions 304. Range Sum Query 2D - Immutable (Java版; Medium) 题目描述 Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its...

littlehaes的博客 254

【leetcode】304. Range Sum Query 2D - Immutable

题目: 思路: 与【leetcode】303. Range Sum Query - Immutable思路一样,都是求前几项之和,只不过从一维扩展到了二维。 代码实现: class NumMatrix { public: vector<vector<int>> dp; NumMatrix(vector<vector<int>>& matrix){ int rows = matrix.size();

zxc120389574的博客 182

leetcode(304) Range Sum Query 2D - Immutable

题目链接:https://leetcode.com/problems/range-sum-query-2d-immutable/ Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lowe

specialshoot的博客 746

【LeetCode 304】 Range Sum Query 2D - Immutable

题目描述 Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). Range Sum Query 2D The above rectang...

iCode_girl的博客 197

LeetCode - 304. Range Sum Query 2D - Immutable

前面已经做过一道Range Sum Query - Immutable的题目,当时我们采用的方法是新建一个数组存储nums中从0到当前index的元素的和,这样在sumRange方法中我们可以在O(1)的时间中得到结果,在题目要求的sumRange多次调用的情况下非常方便。 这里我们同样想要采用相似的方法,于是我们需要另外新建一个二维数组来存储和而不是单个的元素,2D情况下的sumRange分析

找不到工作了... 1325

[leetcode]304. Range Sum Query 2D - Immutable

题目链接:https://leetcode-cn.com/problems/range-sum-query-2d-immutable/submissions/ 方法1:动态规划 取数组m[][],其中m[i][j]意为从matrix[0][0]到matrix[i][j]这个区域的和. public class NumMatrix2 { int[][] m; publi...

HeinSven的博客 118

leetcode [304]Range Sum Query 2D - Immutable

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red border...

weixin_30396699的博客 68
上一篇: LeetCode219. Contains Duplicate II
下一篇: PAT1078 Hashing (25)
_IanXiao
博客等级 码龄12年 84粉丝 241原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值