Global and Local Inversions LeetCode solution in Rust

1
impl Solution {
2
pub fn is_ideal_permutation(nums: Vec<i32>) -> bool {
3
fn _is_ideal_permutation(nums: Vec<i32>) -> Option<bool> {
4
let mut max = 0;
5
for i in 0..nums.len().checked_sub(2)? {
6
max = std::cmp::max(max, *nums.get(i)?);
7
if max > *nums.get(i + 2)? {
8
return Some(false);
9
}
10
}
11
Some(true)
12
}
13
_is_ideal_permutation(nums).unwrap_or(true)
14
}
15
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0