File tree 1 file changed +7
-6
lines changed
scripts/algorithms/S/Sum of Beauty in the Array
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 9 ms (Top 73.89%) | Memory: 94 MB (Top 67.52%)
1
2
class Solution {
2
3
public int sumOfBeauties (int [] nums ) {
3
4
boolean [] left = new boolean [nums .length ];
4
5
boolean [] right = new boolean [nums .length ];
5
-
6
+
6
7
left [0 ] = true ;
7
8
int leftMax = nums [0 ];
8
9
for (int i = 1 ; i < nums .length ; i ++) {
@@ -11,7 +12,7 @@ public int sumOfBeauties(int[] nums) {
11
12
leftMax = nums [i ];
12
13
}
13
14
}
14
-
15
+
15
16
right [nums .length -1 ] = true ;
16
17
int rightMin = nums [nums .length -1 ];
17
18
for (int i = nums .length -2 ; i >= 0 ; i --) {
@@ -20,18 +21,18 @@ public int sumOfBeauties(int[] nums) {
20
21
rightMin = nums [i ];
21
22
}
22
23
}
23
-
24
+
24
25
int beautyCount = 0 ;
25
26
for (int i = 1 ; i < nums .length -1 ; i ++) {
26
27
if (left [i ] && right [i ]) {
27
28
beautyCount += 2 ;
28
29
}
29
-
30
+
30
31
else if (nums [i -1 ] < nums [i ] && nums [i ] < nums [i +1 ]) {
31
32
beautyCount += 1 ;
32
33
}
33
-
34
+
34
35
}
35
36
return beautyCount ;
36
37
}
37
- }
38
+ }
You can’t perform that action at this time.
0 commit comments