1
impl Solution {
2
pub fn sum_of_beauties(nums: Vec<i32>) -> i32 {
3
let n = nums.len();
4
let mut l_max = vec![i32::MIN; n];
5
let mut r_min = vec![i32::MAX; n];
6
let mut res = 0;
7

8
l_max[0] = nums[0];
9
r_min[n - 1] = nums[n - 1];
10

11
for i in 1..n {
12
l_max[i] = l_max[i - 1].max(nums[i - 1]);
13
}
14
for i in (0..n - 1).rev() {
15
r_min[i] = r_min[i + 1].min(nums[i + 1]);
16
}
17

18
for i in 1..n - 1 {
19
if l_max[i] < nums[i] && nums[i] < r_min[i] {
20
res += 2;
21
} else if nums[i - 1] < nums[i] && nums[i] < nums[i + 1] {
22
res += 1;
23
}
24
}
25

26
res
27
}
28
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0