Skip to content

Commit 887aee3

Browse files
committed
pass problem 1423 - maximum points you can obtain from cards
1 parent bf7b237 commit 887aee3

File tree

1 file changed

+21
-0
lines changed
  • double_pointers/maximum_points_you_can_obtain_from_cards

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package double_pointers.maximum_points_you_can_obtain_from_cards;
2+
3+
/**
4+
* @author Bota5ky
5+
* @link <a href="https://leetcode.cn/problems/maximum-points-you-can-obtain-from-cards/">1423. 可获得的最大点数</a>
6+
* @since 2023-11-03 20:57
7+
*/
8+
class Solution {
9+
public int maxScore(int[] cardPoints, int k) {
10+
int max = 0;
11+
for (int i = 0; i < k; i++) {
12+
max += cardPoints[i];
13+
}
14+
var sum = max;
15+
for (int i = k - 1, j = cardPoints.length - 1; i >= 0; i--) {
16+
sum = sum - cardPoints[i] + cardPoints[j--];
17+
max = Math.max(max, sum);
18+
}
19+
return max;
20+
}
21+
}

0 commit comments

Comments
 (0)