-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbird_mountain.rs
More file actions
31 lines (31 loc) · 936 Bytes
/
bird_mountain.rs
File metadata and controls
31 lines (31 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn peak_height(m: &[&str]) -> u32 {
let mut a = m
.iter()
.cloned()
.map(|e| e.chars().collect::<Vec<_>>())
.collect::<Vec<_>>();
let N = a.len() as isize;
let M = a[0].len() as isize;
let mut h = 0;
while a.iter().any(|t| t.contains(&'^')) {
let mut v = m
.iter()
.cloned()
.map(|e| e.chars().collect::<Vec<_>>())
.collect::<Vec<_>>();
for i in 0..N {
for j in 0..M {
for (y, x) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)] {
if (i == 0 || i == N - 1 || j == 0 || j == M - 1)
|| (y >= 0 && y < N && x >= 0 && x < M && a[y as usize][x as usize] == ' ')
{
v[i as usize][j as usize] = ' ';
}
}
}
}
a = v;
h += 1;
}
h
}