Skip to content

Commit b23360f

Browse files
authored
Update 2640-find-the-score-of-all-prefixes-of-an-array.js
1 parent 0a7f9c7 commit b23360f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

2640-find-the-score-of-all-prefixes-of-an-array.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* @return {number[]}
44
*/
55
const findPrefixScore = function(nums) {
6-
let pre = [];
7-
let m = 0, s = 0;
8-
for(let x of nums) {
9-
m = Math.max(m, x);
10-
s += x + m;
11-
pre.push(s);
6+
const { max } = Math
7+
const res = []
8+
let ma = 0, sum = 0
9+
for(const e of nums) {
10+
ma = max(e, ma)
11+
sum += ma + e
12+
res.push(sum)
1213
}
13-
return pre;
14+
15+
return res
1416
};

0 commit comments

Comments
 (0)