diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 53e765c..a317e22 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -220,4 +220,5 @@ mod p698_partition_to_k_equal_sum_subsets; 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; \ No newline at end of file +mod p3153_sum_of_digit_differences_of_all_pairs; +mod p3127_make_a_square_with_the_same_color; \ No newline at end of file diff --git a/src/problem/p3127_make_a_square_with_the_same_color.rs b/src/problem/p3127_make_a_square_with_the_same_color.rs new file mode 100644 index 0000000..15670a1 --- /dev/null +++ b/src/problem/p3127_make_a_square_with_the_same_color.rs @@ -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>) -> 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() { + } +}