当前位置:网站首页>554. brick wall
554. brick wall
2022-06-11 07:02:00 【Not coriander】
You have a rectangle in front of you 、 from n A brick wall made of rows of bricks . These bricks are the same height ( That's one unit high ) But the width is different . The sum of the widths of each row of bricks is equal .
You're going to draw one now The top-down Of 、 Through the least Vertical line of brick . If you draw a line that just goes through the edge of the brick , Not through this brick . You can't draw a line along one of the two vertical edges of the wall , It's obviously not through a brick .
Give you a two-dimensional array wall , This array contains information about the wall . among ,wall[i] Is an array representing the width of each brick from left to right . You need to figure out how to draw this line The least number of bricks passed through , And back to The number of bricks passed through .
Example 1:
Input :wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]
Output :2
Example 2:
Input :wall = [[1],[1],[1]]
Output :3
Tips :
n == wall.length
1 <= n <= 104
1 <= wall[i].length <= 104
1 <= sum(wall[i].length) <= 2 * 104
For each line i ,sum(wall[i]) It's the same
1 <= wall[i][j] <= 231 - 1
class Solution {
public:
int leastBricks(vector<vector<int>>& wall) {
map<int,int>m;
int len=wall.size();
for(int i=0;i<len;i++){
int len2=wall[i].size();
int x=0;
for(int j=0;j<len2-1;j++){
x+=wall[i][j];
m[x]++;
}
}
int max=0;
for(map<int,int>::iterator it=m.begin();it!=m.end();it++){
if(it->second>max)max=it->second;
}
return len-max;
}
};
边栏推荐
- 无心剑汉英双语诗001.《爱》
- 你知道IT人才外派服务报价是怎样的么?建议程序员也了解下
- Summary and review
- Summary of string processing skills III
- Promise details
- 数学方法论的含义和研究意义
- Difference between byte and bit
- Leetcode hot topic 100 topic 21-25 solution
- Practice: how to reasonably design functions to solve practical problems in software development (II) -- improving reusability
- About daily report plan
猜你喜欢

client-go gin的简单整合六-list-watch二(关于Rs与Pod以及Deployment的完善)

教育专家王中泽老师:家庭教育重在自己成长

Shuttle container component
![Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]](/img/0d/2de3413fcb77ac2bd093677035f2e7.jpg)
Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]

Stack -- one of two common linear structures of linear structure

First day of database

A highly controversial issue

WPF 数据绑定(四)

Latex various arrows / arrows with text labels / variable length arrows
![[并发进阶]——线程池总结](/img/69/dc8146dafc30f8a8efa012b67aa05c.png)
[并发进阶]——线程池总结
随机推荐
Cross-Modal Pattern-Propagation for RGB-T Tracking
saltstack部署lnmp
教育专家王中泽老师多年经验分享:家庭教育不是附庸品
【Matlab图像加密解密】混沌序列图像加密解密(含相关性检验)【含GUI源码 1862期】
Latex various arrows / arrows with text labels / variable length arrows
Wan Zichang's article shows you promise
Object. Specific implementation and difference between create() and new
News web page display
Pytest自动化测试-简易入门教程(01)
Web API、DOM
Leetcode-141. Linked List Cycle
Bat (batch processing) processing special symbols (exclamation point, percent sign), etc
Group arrays by a specified size
latex 各种箭头/带文字标号的箭头/可变长箭头
Saltstack deployment ZABBIX state file writing
Notice on organizing the application for the first edition of Ningbo key software in 2022
[matlab printed character recognition] OCR printed letter + number recognition [including source code 1861]
Explain the difference between void 0 and undefined
Listen to the left width of the browser to calculate the distance
A highly controversial issue