20240829 finished.

This commit is contained in:
jackfiled 2024-08-29 11:12:15 +08:00
parent e9eeb2d008
commit 31ceeb32cd
2 changed files with 44 additions and 1 deletions

View File

@ -219,3 +219,4 @@ mod p3146_permutation_difference_between_two_strings;
mod p698_partition_to_k_equal_sum_subsets; mod p698_partition_to_k_equal_sum_subsets;
mod p3134_find_the_median_of_the_uniqueness_array; mod p3134_find_the_median_of_the_uniqueness_array;
mod p3144_minimum_substring_partition_of_equal_character_frequency; mod p3144_minimum_substring_partition_of_equal_character_frequency;
mod p3142_check_if_grid_satisfies_conditions;

View File

@ -0,0 +1,42 @@
/**
* [3142] Check if Grid Satisfies Conditions
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn satisfies_conditions(grid: Vec<Vec<i32>>) -> bool {
let (m, n) = (grid.len(), grid[0].len());
for i in 0..n {
if i != 0 && grid[0][i] == grid[0][i - 1] {
return false;
}
for j in 1..m {
if grid[j][i] != grid[j - 1][i] {
return false;
}
}
}
true
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_3142() {
assert!(Solution::satisfies_conditions(vec![vec![1, 0, 2], vec![1, 0, 2]]));
assert!(!Solution::satisfies_conditions(vec![vec![1, 1, 1], vec![0, 0, 0]]));
assert!(Solution::satisfies_conditions(vec![vec![0]]));
assert!(!Solution::satisfies_conditions(vec![vec![1], vec![2], vec![3]]));
}
}