Skip to content

Commit d43c75f

Browse files
committed
modify code
1 parent fe22b8c commit d43c75f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/class25/Code05_CountSubmatricesWithAllOnes.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ public static int numSubmat(int[][] mat) {
1919

2020
}
2121

22+
// 比如
23+
// 1
24+
// 1
25+
// 1 1
26+
// 1 1 1
27+
// 1 1 1
28+
// 1 1 1
29+
//
30+
// 2 .... 6 .... 9
31+
// 如上图,假设在6位置,1的高度为6
32+
// 在6位置的左边,离6位置最近、且小于高度6的位置是2,2位置的高度是3
33+
// 在6位置的右边,离6位置最近、且小于高度6的位置是9,9位置的高度是4
34+
// 此时我们求什么?
35+
// 1) 求在3~8范围上,必须以高度6作为高的矩形,有几个?
36+
// 2) 求在3~8范围上,必须以高度5作为高的矩形,有几个?
37+
// 也就是说,<=4的高度,一律不求
38+
// 那么,1) 求必须以位置6的高度6作为高的矩形,有几个?
39+
// 3..3 3..4 3..5 3..6 3..7 3..8
40+
// 4..4 4..5 4..6 4..7 4..8
41+
// 5..5 5..6 5..7 5..8
42+
// 6..6 6..7 6..8
43+
// 7..7 7..8
44+
// 8..8
45+
// 这么多!= 21 = (9 - 2 - 1) * (9 - 2) / 2
46+
// 这就是任何一个数字从栈里弹出的时候,计算矩形数量的方式
2247
public static int countFromBottom(int[] height) {
2348
if (height == null || height.length == 0) {
2449
return 0;

0 commit comments

Comments
 (0)