Skip to content

Commit 913b9b2

Browse files
committed
Runtime: 155 ms (Top 80.49%) | Memory: 60.8 MB (Top 63.42%)
1 parent fc9961a commit 913b9b2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
// Runtime: 155 ms (Top 80.49%) | Memory: 60.8 MB (Top 63.42%)
12
/**
23
* @param {number[]} nums
34
* @return {number}
45
*/
56
var sumOfBeauties = function(nums) {
67
let min = nums[0], max = Infinity, maxArr = [], total = 0;
7-
8-
// Creating an array, which will keep the record of minimum values from last index
8+
9+
// Creating an array, which will keep the record of minimum values from last index
910
for(let i=nums.length-1; i>1; i--) {
1011
if(nums[i] < max) max = nums[i];
1112
maxArr.push(max);
1213
}
1314

14-
// iterating through array to check the given conditions
15+
// iterating through array to check the given conditions
1516
for(let i=1; i<nums.length-1; i++) {
16-
17-
// Keeping a record of max value from all index < i
17+
18+
// Keeping a record of max value from all index < i
1819
if(nums[i-1] > min) min = nums[i-1];
19-
20-
// Checking conditions
20+
21+
// Checking conditions
2122
if(nums[i] < maxArr.pop() && min < nums[i]) total += 2;
2223
else if(nums[i-1] < nums[i] && nums[i] < nums[i+1]) total += 1;
2324
}
24-
25+
2526
return total;
26-
};
27+
};

0 commit comments

Comments
 (0)