554. Brick Wall最少的穿墙个数

Posted 排序和map

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了554. Brick Wall最少的穿墙个数相关的知识,希望对你有一定的参考价值。

[抄题]:

There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks.

The brick wall is represented by a list of rows. Each row is a list of integers representing the width of each brick in this row from left to right.

If your line go through the edge of a brick, then the brick is not considered as crossed. You need to find out how to draw the line to cross the least bricks and return the number of crossed bricks.

You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks.

Example:

Input: 
[[1,2,2,1],
 [3,1,2],
 [1,3,2],
 [2,4],
 [3,1,2],
 [1,3,1,1]]
Output: 2
Explanation: 

技术分享图片

 [暴力解法]:

时间分析:

空间分析:

 [优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

最后一条缝不算,< i < list.size() - 1

[思维问题]:

不知道怎么用数学表达:(最少)穿墙个数 = 总墙数 - (最多)的个数

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

  [五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O() Space complexity: O()

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[算法思想:递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

 [代码风格] :

以上是关于554. Brick Wall最少的穿墙个数的主要内容,如果未能解决你的问题,请参考以下文章

554. Brick Wall

[leetcode-554-Brick Wall]

Leetcode 554: Brick Wall

554. Brick Wall

554. Brick Wall 砖墙

LeetCode 0554. 砖墙