Skip to content

Commit 45021ff

Browse files
authored
Added solution for 2640
1 parent c20841e commit 45021ff

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::cmp::max;
2+
3+
impl Solution {
4+
// Keep track of highest num and sum of score instead of calculating score vector everytime. For every iteration of nums, add previous score to highest_num and current num
5+
pub fn find_prefix_score(nums: Vec<i32>) -> Vec<i64> {
6+
let mut ans:Vec<i64> = Vec::new();
7+
let mut highest_num = 0;
8+
let mut score = 0;
9+
10+
for num in nums {
11+
highest_num = max(highest_num, num as i64);
12+
score += (highest_num + num as i64);
13+
ans.push(score);
14+
}
15+
16+
return ans;
17+
}
18+
}

0 commit comments

Comments
 (0)