554. Brick Wall Medium
1/**
2 * [554] Brick Wall
3 *
4 * There is a rectangular brick wall in front of you with n rows of bricks. The i^th row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.
5 * Draw a vertical line from the top to the bottom and cross the least bricks. If your line goes through the edge of a brick, then the brick is not considered as crossed. 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.
6 * Given the 2D array wall that contains the information about the wall, return the minimum number of crossed bricks after drawing such a vertical line.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/cutwall-grid.jpg" style="width: 493px; height: 577px;" />
10 * Input: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]
11 * Output: 2
12 *
13 * Example 2:
14 *
15 * Input: wall = [[1],[1],[1]]
16 * Output: 3
17 *
18 *
19 * Constraints:
20 *
21 * n == wall.length
22 * 1 <= n <= 10^4
23 * 1 <= wall[i].length <= 10^4
24 * 1 <= sum(wall[i].length) <= 2 * 10^4
25 * sum(wall[i]) is the same for each row i.
26 * 1 <= wall[i][j] <= 2^31 - 1
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/brick-wall/
32// discuss: https://leetcode.com/problems/brick-wall/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn least_bricks(wall: Vec<Vec<i32>>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_554() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.