20240829 finished.
This commit is contained in:
parent
e9eeb2d008
commit
31ceeb32cd
|
@ -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;
|
42
src/problem/p3142_check_if_grid_satisfies_conditions.rs
Normal file
42
src/problem/p3142_check_if_grid_satisfies_conditions.rs
Normal 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]]));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user