non-decreasing-array
This commit is contained in:
parent
8976c0171f
commit
e061a8602f
|
@ -0,0 +1,19 @@
|
|||
impl Solution {
|
||||
pub fn check_possibility(nums: Vec<i32>) -> bool {
|
||||
nums.windows(2)
|
||||
.scan(i32::MIN, |max, n| {
|
||||
*max = n[0].max(*max);
|
||||
Some(n[1] < *max)
|
||||
})
|
||||
.filter(|&result| result)
|
||||
.count() <= 1 ||
|
||||
nums.windows(2)
|
||||
.rev()
|
||||
.scan(i32::MAX, |min, n| {
|
||||
*min = n[1].min(*min);
|
||||
Some(n[0] > *min)
|
||||
})
|
||||
.filter(|&result| result)
|
||||
.count() <= 1
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue