944. Maximum Submatrix

Description

Given an n x n matrix of positive and negative integers, find the submatrix with the largest possible sum.

Example

Example1

Input: 

matrix = [

    [1,3,-1],

    [2,3,-2],

    [-1,-2,-3]

]

Output: 9

Explanation:

the submatrix with the largest possible sum is:

[

    [1,3],

    [2,3]

]

Example2

Input: 

matrix = [

    [1,1,1],

    [1,1,1],

    [1,1,1]

]

Output: 9

Explanation:

the submatrix with the largest possible sum is:

[

    [1,1,1],

    [1,1,1],

    [1,1,1]

]

思路:

对二维数组从列的维度求和进行了降维,matrix = [

    [1,3,-1],

    [2,3,-2],

    [-1,-2,-3]

]

转化成[1, 3, -1] [1+2, 3+3, -1-2][1+2+3,3+3-2, -1-2-3][2,3,-2][2-1, 3-2, -2-3][-1,-2,-3]一系列一维数组,然后对降维的数组求和最大的子数组,用的是easy题中求和最大子数组的思路。

代码:


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,183评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,516评论 0 23
  • redis的命令时间是微秒级别 pipeline 每次条数要控制(网络),减小网络通信时间 jedis 使用pip...
    文刀雨阅读 4,766评论 0 0
  • 设计师图书导航:http://hao.uisdc.com/book/ 知乎设计师:https://www.zhih...
    NeverMore_Love阅读 2,593评论 0 0
  • 种子应该是这个时代最神奇的存在,假如说有化腐朽为神奇的力量一点也不过,如果不信,你看那小小的两个细胞如何演化成人类...
    承谦阅读 1,175评论 0 0

友情链接更多精彩内容