20240831 finished.

This commit is contained in:
jackfiled 2024-08-31 13:21:46 +08:00
parent 1945a07426
commit f563eaa22c
2 changed files with 47 additions and 1 deletions

View File

@ -221,3 +221,4 @@ mod p3134_find_the_median_of_the_uniqueness_array;
mod p3144_minimum_substring_partition_of_equal_character_frequency;
mod p3142_check_if_grid_satisfies_conditions;
mod p3153_sum_of_digit_differences_of_all_pairs;
mod p3127_make_a_square_with_the_same_color;

View File

@ -0,0 +1,45 @@
/**
* [3127] Make a Square with the Same Color
*/
pub struct Solution {}
// submission codes start here
const DELTA: [(usize, usize); 4] = [(0, 0), (0, 1), (1, 0), (1, 1)];
impl Solution {
pub fn can_make_square(grid: Vec<Vec<char>>) -> bool {
for i in 0..2 {
for j in 0.. 2 {
let mut white: i32 = 0;
let mut black: i32 = 0;
for (x, y) in DELTA {
match grid[i + x][j + y] {
'B' => black += 1,
'W' => white += 1,
_ => {}
}
}
if white.abs_diff(black) == 2 || white.abs_diff(black) == 4 {
return true;
}
}
}
false
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_3127() {
}
}