20240831 finished.
This commit is contained in:
parent
1945a07426
commit
f563eaa22c
|
@ -220,4 +220,5 @@ 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;
|
mod p3142_check_if_grid_satisfies_conditions;
|
||||||
mod p3153_sum_of_digit_differences_of_all_pairs;
|
mod p3153_sum_of_digit_differences_of_all_pairs;
|
||||||
|
mod p3127_make_a_square_with_the_same_color;
|
45
src/problem/p3127_make_a_square_with_the_same_color.rs
Normal file
45
src/problem/p3127_make_a_square_with_the_same_color.rs
Normal 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() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user