Skip to content

Commit

Permalink
1861
Browse files Browse the repository at this point in the history
  • Loading branch information
warycat committed Nov 23, 2024
1 parent 0111698 commit 25da7a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions leetcode/src/d18/_1861_rotating_the_box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
struct Solution;

impl Solution {
pub fn rotate_the_box(b: Vec<Vec<char>>) -> Vec<Vec<char>> {
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<char>> = vec_vec_char![['#', '.', '#']];
let a: Vec<Vec<char>> = vec_vec_char![['.'], ['#'], ['#']];
assert_eq!(Solution::rotate_the_box(b), a);
let b: Vec<Vec<char>> = vec_vec_char![['#', '.', '*', '.'], ['#', '#', '*', '.']];
let a: Vec<Vec<char>> = vec_vec_char![['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']];
assert_eq!(Solution::rotate_the_box(b), a)
}
2 changes: 2 additions & 0 deletions leetcode/src/d18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25da7a5

Please sign in to comment.