File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
solution/1500-1599/1504.Count Submatrices With All Ones Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,44 @@ function numSubmat(mat: number[][]): number {
228
228
}
229
229
```
230
230
231
+ #### Rust
232
+
233
+ ``` rust
234
+ impl Solution {
235
+ pub fn num_submat (mat : Vec <Vec <i32 >>) -> i32 {
236
+ let m = mat . len ();
237
+ let n = mat [0 ]. len ();
238
+ let mut g = vec! [vec! [0 ; n ]; m ];
239
+
240
+ for i in 0 .. m {
241
+ for j in 0 .. n {
242
+ if mat [i ][j ] == 1 {
243
+ if j == 0 {
244
+ g [i ][j ] = 1 ;
245
+ } else {
246
+ g [i ][j ] = 1 + g [i ][j - 1 ];
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ let mut ans = 0 ;
253
+ for i in 0 .. m {
254
+ for j in 0 .. n {
255
+ let mut col = i32 :: MAX ;
256
+ let mut k = i as i32 ;
257
+ while k >= 0 && col > 0 {
258
+ col = col . min (g [k as usize ][j ]);
259
+ ans += col ;
260
+ k -= 1 ;
261
+ }
262
+ }
263
+ }
264
+ ans
265
+ }
266
+ }
267
+ ```
268
+
231
269
#### JavaScript
232
270
233
271
``` js
You can’t perform that action at this time.
0 commit comments