Skip to content

Commit fcff5f8

Browse files
authored
Create maximum-points-you-can-obtain-from-cards.py
1 parent 6396f53 commit fcff5f8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxScore(self, cardPoints, k):
6+
"""
7+
:type cardPoints: List[int]
8+
:type k: int
9+
:rtype: int
10+
"""
11+
result, total, curr, left = float("inf"), 0, 0, 0
12+
for right, point in enumerate(cardPoints):
13+
total += point
14+
curr += point
15+
if right-left+1 > len(cardPoints)-k:
16+
curr -= cardPoints[left]
17+
left += 1
18+
if right-left+1 == len(cardPoints)-k:
19+
result = min(result, curr)
20+
return total-result

0 commit comments

Comments
 (0)