File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,8 @@ public void reverseString(char[] s) {
4
4
int end = s .length - 1 ;
5
5
while (start < end ) {
6
6
char temp = s [start ];
7
- s [start ] = s [end ];
8
- s [end ] = temp ;
9
- start ++;
10
- end --;
7
+ s [start ++] = s [end ];
8
+ s [end --] = temp ;
11
9
}
12
10
}
13
11
}
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int numSubmat (int [][] mat ) {
3
+ int m = mat .length ;
4
+ int n = mat [0 ].length ;
5
+ int res = 0 ;
6
+ for (int i = 0 ; i < m ; i ++) {
7
+ int [] arr = new int [n ];
8
+ Arrays .fill (arr , 1 );
9
+ for (int j = i ; j < m ; j ++) {
10
+ for (int k = 0 ; k < n ; k ++) {
11
+ arr [k ] &= mat [j ][k ];
12
+ }
13
+ res += countOneRow (arr );
14
+ }
15
+ }
16
+ return res ;
17
+ }
18
+
19
+ private int countOneRow (int [] A ) {
20
+ int res = 0 , length = 0 ;
21
+ for (int i = 0 ; i < A .length ; ++i ) {
22
+ length = (A [i ] == 0 ? 0 : length + 1 );
23
+ res += length ;
24
+ }
25
+ return res ;
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments