当前位置:网站首页>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;
}
};
边栏推荐
- Henan college entrance examination vs Tianjin college entrance examination (2008-2021)
- Promise details
- 商汤科技积极复工,将大力投入数字哨兵的产能和部署
- [probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen
- A highly controversial issue
- Drawing with qpainter
- Use of qscriptengine class
- [turn] flying clouds_ Qt development experience
- Summary of string processing skills II
- Luogu p1091 chorus formation (longest ascending subsequence)
猜你喜欢

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

Open source cartoon server mango
![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]
![JS implementation of Hill sort of graphic insertion sort [with source code]](/img/5a/b89fd5a0ebbc7ca17cc3e1fcb37c8f.jpg)
JS implementation of Hill sort of graphic insertion sort [with source code]

Nodejs database (Part 2)

教育专家王中泽老师一招解决学生问题

Explain the difference between void 0 and undefined

LEARNING TARGET-ORIENTED DUAL ATTENTION FOR ROBUST RGB-T TRACKING

Simple integration of client go gin six list watch two (about the improvement of RS, pod and deployment)

Henan college entrance examination vs Tianjin college entrance examination (2008-2021)
随机推荐
Zabbix 监控主机是否在线
1266_ Implementation analysis of FreeRTOS scheduler startup code
Shuttle inside and outside margins
Grayscale publishing through ingress
开源漫画服务器Mango
June training (day 11) - matrix
saltstack部署zabbix状态文件编写
sql查询问题,只显示列名 不显示数据
Nodejs database (Part 2)
mybaits-puls 在xml文件中写sql语句 会报错 Invalid bound statement (not found):
通过 Ingress 进行灰度发布
Matplotlib,设置坐标刻度大小,字体/设置图例大小及字体/设置纵横坐标名称及字体及大小
Duality-Gated Mutual Condition Network for RGBT Tracking
AtomicInteger原子操作类
Xunwei dry goods | Ruixin micro rk3568 development board TFTP & NFS writing (Part 1)
latex 各种箭头/带文字标号的箭头/可变长箭头
[MATLAB image fusion] particle swarm optimization adaptive multispectral image fusion [including source code phase 004]
Common modules of saltstack
JS implementation of Hill sort of graphic insertion sort [with source code]
Pytest自动化测试-简易入门教程(01)