We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2079eb1 commit bdac804Copy full SHA for bdac804
1423/main.rs
@@ -0,0 +1,15 @@
1
+/// https://dev.to/seanpgallivan/solution-maximum-points-you-can-obtain-from-cards-2no
2
+impl Solution {
3
+ pub fn max_score(card_points: Vec<i32>, k: i32) -> i32 {
4
+ let mut total = card_points.iter().take(k as usize).sum::<i32>();
5
+ let mut best = total;
6
+ let (mut i, mut j) = (k - 1, card_points.len() - 1);
7
+ while i >= 0 {
8
+ total += card_points[j] - card_points[i as usize];
9
+ best = best.max(total);
10
+ i -= 1;
11
+ j -= 1;
12
+ }
13
+ best
14
15
+}
0 commit comments