554. Brick Wall
来源:互联网 发布:销售数据分析表格模板 编辑:程序博客网 时间:2024/05/16 06:24
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: 2Explanation:
Note:
- The width sum of bricks in different rows are the same and won't exceed INT_MAX.
- The number of bricks in each row is in range [1,10,000]. The height of wall is in range [1,10,000]. Total number of bricks of the wall won't exceed 20,000.
package l554;import java.util.HashMap;import java.util.List;import java.util.Map;public class Solution { public int leastBricks(List<List<Integer>> wall) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(List<Integer> l : wall) { int cnt = 0; for(int i=0; i<l.size()-1; i++) { cnt += l.get(i); if(!map.containsKey(cnt))map.put(cnt, 1); elsemap.put(cnt, map.get(cnt)+1); } } int max = 0; for(int i : map.keySet()) max = Math.max(max, map.get(i)); return wall.size() - max; }}
- Leetcode-554. Brick Wall
- [leetcode] 554. Brick Wall
- 554. Brick Wall
- 554. Brick Wall
- [LeetCode]554. Brick Wall
- 554. Brick Wall
- [LeetCode]554. Brick Wall
- 554. Brick Wall
- [leetcode]554. Brick Wall
- 554. Brick Wall
- 554. Brick Wall
- [LeetCode] 554. Brick Wall
- leetcode 554. Brick Wall
- 554. Brick Wall。
- 554. Brick Wall
- 554. Brick Wall (map)
- Brick Wall
- Brick Wall
- Spring使用注解事务管理
- 前言
- html文档流
- vue2移动端上传,预览,压缩图片,解决拍照旋转问题
- 2016年蓝桥杯决赛 机器人塔(超时)
- 554. Brick Wall
- winform 获取需要上传excel路径
- 递归橘子问题
- DP46题
- POJ1064-Cable master
- HDU 1272 小希的迷宫 题解
- java 编程思想课后题(第三章)
- 今天做到一道面试题:Android开发关于ANR问题
- continue to wait, or press S to skip mounting or M for manual recovery