Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c4ad4c4

Browse files
committed
Added 1 solution & modified 1 solution
1 parent 1ea1960 commit c4ad4c4

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

Easy/Reverse String.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ public void reverseString(char[] s) {
44
int end = s.length - 1;
55
while (start < end) {
66
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;
119
}
1210
}
1311
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)