Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 42d042f

Browse files
Time: 1520 ms (71.71%), Space: 50.3 MB (74.63%) - LeetHub
1 parent 9f8aa3c commit 42d042f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def maxPoints(self, points: List[List[int]]) -> int:
3+
m, n = len(points), len(points[0])
4+
5+
# Initialize the dp array with the first row of points
6+
dp = points[0]
7+
8+
# Process each row
9+
for i in range(1, m):
10+
left_max = [0] * n
11+
right_max = [0] * n
12+
13+
# Compute the left max values
14+
left_max[0] = dp[0]
15+
for j in range(1, n):
16+
left_max[j] = max(left_max[j-1] - 1, dp[j])
17+
18+
# Compute the right max values
19+
right_max[n-1] = dp[n-1]
20+
for j in range(n-2, -1, -1):
21+
right_max[j] = max(right_max[j+1] - 1, dp[j])
22+
23+
# Update dp for the current row
24+
for j in range(n):
25+
dp[j] = points[i][j] + max(left_max[j], right_max[j])
26+
27+
# The maximum value in dp array is the result
28+
return max(dp)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /