We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bf7b237 commit 887aee3Copy full SHA for 887aee3
double_pointers/maximum_points_you_can_obtain_from_cards/Solution.java
@@ -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