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 0066f11 commit 1c93a91Copy full SHA for 1c93a91
Python/maximum-number-of-points-with-cost.py
@@ -0,0 +1,24 @@
1
+# Time: O(m * n)
2
+# Space: O(n)
3
+
4
+class Solution(object):
5
+ def maxPoints(self, points):
6
+ """
7
+ :type points: List[List[int]]
8
+ :rtype: int
9
10
+ dp = points[0]
11
+ for i in xrange(1, len(points)):
12
+ prefix = [0]*len(points[i])
13
+ prefix[0] = dp[0]
14
+ for j in xrange(1, len(points[i])):
15
+ prefix[j] = max(prefix[j-1], dp[j]+j)
16
+ suffix = [0]*len(points[i])
17
+ suffix[-1] = dp[-1]-(len(points[i])-1)
18
+ for j in reversed(xrange(len(points[i])-1)):
19
+ suffix[j] = max(suffix[j+1], dp[j]-j)
20
+ new_dp = [0]*len(points[i])
21
+ for j in xrange(len(points[i])):
22
+ new_dp[j] = max(prefix[j]-j, suffix[j]+j)+points[i][j]
23
+ dp = new_dp
24
+ return max(dp)
0 commit comments