Skip to content

Commit 23b0878

Browse files
authored
feat: add dart solution to lc problem: No.1423 (#2561)
No.1423.Maximum Points You Can Obtain from Cards
1 parent 4b23457 commit 23b0878

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ class Solution {
278278
}
279279
```
280280

281+
```dart
282+
class Solution {
283+
int maxScore(List<int> cardPoints, int k) {
284+
int n = cardPoints.length;
285+
int s = cardPoints.sublist(n - k).reduce((a, b) => a + b);
286+
int ans = s;
287+
for (int i = 0; i < k; ++i) {
288+
s += cardPoints[i] - cardPoints[n - k + i];
289+
ans = s > ans ? s : ans;
290+
}
291+
return ans;
292+
}
293+
}
294+
```
295+
281296
<!-- tabs:end -->
282297

283298
<!-- end -->

solution/1400-1499/1423.Maximum Points You Can Obtain from Cards/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,21 @@ class Solution {
264264
}
265265
```
266266

267+
```dart
268+
class Solution {
269+
int maxScore(List<int> cardPoints, int k) {
270+
int n = cardPoints.length;
271+
int s = cardPoints.sublist(n - k).reduce((a, b) => a + b);
272+
int ans = s;
273+
for (int i = 0; i < k; ++i) {
274+
s += cardPoints[i] - cardPoints[n - k + i];
275+
ans = s > ans ? s : ans;
276+
}
277+
return ans;
278+
}
279+
}
280+
```
281+
267282
<!-- tabs:end -->
268283

269284
<!-- end -->

0 commit comments

Comments
 (0)