Skip to content

Commit 25da7a5

Browse files
committed
1861
1 parent 0111698 commit 25da7a5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: leetcode/src/d18/_1861_rotating_the_box.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
struct Solution;
2+
3+
impl Solution {
4+
pub fn rotate_the_box(b: Vec<Vec<char>>) -> Vec<Vec<char>> {
5+
let n = b.len();
6+
let m = b[0].len();
7+
let mut a = vec![];
8+
for _ in 0..m {
9+
a.push(vec!['.'; n]);
10+
}
11+
for i in 0..n {
12+
let mut x = m;
13+
let mut y = m;
14+
for _j in 0..m {
15+
match b[i][x - 1] {
16+
'.' => {}
17+
'*' => {
18+
a[x - 1][n - 1 - i] = '*';
19+
y = x - 1;
20+
}
21+
'#' => {
22+
a[y - 1][n - 1 - i] = '#';
23+
y -= 1;
24+
}
25+
_ => {}
26+
}
27+
x -= 1;
28+
}
29+
}
30+
a
31+
}
32+
}
33+
34+
#[test]
35+
fn test() {
36+
let b: Vec<Vec<char>> = vec_vec_char![['#', '.', '#']];
37+
let a: Vec<Vec<char>> = vec_vec_char![['.'], ['#'], ['#']];
38+
assert_eq!(Solution::rotate_the_box(b), a);
39+
let b: Vec<Vec<char>> = vec_vec_char![['#', '.', '*', '.'], ['#', '#', '*', '.']];
40+
let a: Vec<Vec<char>> = vec_vec_char![['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']];
41+
assert_eq!(Solution::rotate_the_box(b), a)
42+
}

Diff for: leetcode/src/d18/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ mod _1854_maximum_population_year;
6363
//
6464
mod _1859_sorting_the_sentence;
6565
//
66+
mod _1861_rotating_the_box;
67+
//
6668
mod _1863_sum_of_all_subset_xor_totals;
6769
//
6870
mod _1869_longer_contiguous_segments_of_ones_than_zeros;

0 commit comments

Comments
 (0)