1
class Solution {
2
public int sumOfBeauties(int[] nums) {
3
boolean[] left = new boolean[nums.length];
4
boolean[] right = new boolean[nums.length];
5

6
left[0] = true;
7
int leftMax = nums[0];
8
for (int i = 1; i < nums.length; i++) {
9
if (nums[i] > leftMax) {
10
left[i] = true;
11
leftMax = nums[i];
12
}
13
}
14

15
right[nums.length - 1] = true;
16
int rightMin = nums[nums.length - 1];
17
for (int i = nums.length - 2; i >= 0; i--) {
18
if (nums[i] < rightMin) {
19
right[i] = true;
20
rightMin = nums[i];
21
}
22
}
23

24
int beautyCount = 0;
25
for (int i = 1; i < nums.length - 1; i++) {
26
if (left[i] && right[i]) {
27
beautyCount += 2;
28
} else if (nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) {
29
beautyCount += 1;
30
}
31
}
32
return beautyCount;
33
}
34
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0