← 返回 bytedance 的题目列表Brick Wall
类型:online_judge
bytedance
Given a brick wall represented by a 2D array, where each row is an integer array representing the lengths of bricks. Your task is to find a vertical line that crosses the fewest bricks. This line must pass through the gaps between bricks and cannot pass through the middle of a brick. Return the minimum number of bricks that this line has to cross. Assume that the input is non-empty and all elements are positive integers.
Input Format:
wall: A 2D list of integers representing the wall. wall[i][j] is a positive integer denoting the length of the j-th brick in the i-th row.
Output Format:
Return an integer representing the minimum number of bricks the line has to cross.
Example:
Input: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]
Output: 2
Constraints:
The height and width of the wall are at least 1.
The total length of the bricks in each row is the same.
Example
Input
[[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]