forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.rs
31 lines (31 loc) · 900 Bytes
/
Solution.rs
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
impl Solution {
pub fn find_diagonal_order(mat: Vec<Vec<i32>>) -> Vec<i32> {
let (m, n) = (mat.len(), mat[0].len());
let (mut i, mut j) = (0, 0);
(0..m * n)
.map(|_| {
let res = mat[i][j];
if (i + j) % 2 == 0 {
if j == n - 1 {
i += 1;
} else if i == 0 {
j += 1;
} else {
i -= 1;
j += 1;
}
} else {
if i == m - 1 {
j += 1;
} else if j == 0 {
i += 1;
} else {
i += 1;
j -= 1;
}
}
res
})
.collect()
}
}