diff --git a/leetcode/src/d18/_1861_rotating_the_box.rs b/leetcode/src/d18/_1861_rotating_the_box.rs new file mode 100644 index 0000000..95137bc --- /dev/null +++ b/leetcode/src/d18/_1861_rotating_the_box.rs @@ -0,0 +1,42 @@ +struct Solution; + +impl Solution { + pub fn rotate_the_box(b: Vec>) -> Vec> { + let n = b.len(); + let m = b[0].len(); + let mut a = vec![]; + for _ in 0..m { + a.push(vec!['.'; n]); + } + for i in 0..n { + let mut x = m; + let mut y = m; + for _j in 0..m { + match b[i][x - 1] { + '.' => {} + '*' => { + a[x - 1][n - 1 - i] = '*'; + y = x - 1; + } + '#' => { + a[y - 1][n - 1 - i] = '#'; + y -= 1; + } + _ => {} + } + x -= 1; + } + } + a + } +} + +#[test] +fn test() { + let b: Vec> = vec_vec_char![['#', '.', '#']]; + let a: Vec> = vec_vec_char![['.'], ['#'], ['#']]; + assert_eq!(Solution::rotate_the_box(b), a); + let b: Vec> = vec_vec_char![['#', '.', '*', '.'], ['#', '#', '*', '.']]; + let a: Vec> = vec_vec_char![['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]; + assert_eq!(Solution::rotate_the_box(b), a) +} diff --git a/leetcode/src/d18/mod.rs b/leetcode/src/d18/mod.rs index d7670e0..692dcd4 100644 --- a/leetcode/src/d18/mod.rs +++ b/leetcode/src/d18/mod.rs @@ -63,6 +63,8 @@ mod _1854_maximum_population_year; // mod _1859_sorting_the_sentence; // +mod _1861_rotating_the_box; +// mod _1863_sum_of_all_subset_xor_totals; // mod _1869_longer_contiguous_segments_of_ones_than_zeros;