Maximal Square LeetCode solution in Rust
1use std::cmp;23impl Solution {4pub fn maximal_square(matrix: Vec<Vec<char>>) -> i32 {5let rows = matrix.len();6let cols = matrix[0].len();7let mut dp = vec![vec![0; cols + 1]; rows + 1];8let mut max_len: i32 = 0;910for row in 1..=rows {11for col in 1..=cols {12if matrix[row - 1][col - 1] == '1' {13dp[row][col] = 114+ cmp::min(15cmp::min(dp[row - 1][col - 1], dp[row - 1][col]),16dp[row][col - 1],17);18max_len = cmp::max(max_len, dp[row][col] as i32);19}20}21}2223max_len * max_len24}25}