blob: 712324354300e06aff1ead87cd9e049609eae82a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
fn is_min(mat: &[Vec<u64>], col: usize, row: usize) -> bool {
(0..mat.len()).all(|r| mat[r][col] >= mat[row][col])
}
pub fn find_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
let mut res = vec![];
for (row,relem) in input.iter().enumerate() {
let m = relem.iter().max();
for (col,celem) in relem.iter().enumerate() {
if (m == Some(celem)) && is_min(input,col,row) {
res.push((row,col));
}
}
}
res
}
|