Skip to content

Commit 2f117de

Browse files
authored
Create solving-questions-with-brainpower.py
1 parent 24c4d65 commit 2f117de

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
# dp
5+
class Solution(object):
6+
def mostPoints(self, questions):
7+
"""
8+
:type questions: List[List[int]]
9+
:rtype: int
10+
"""
11+
dp = [0]*(len(questions)+1)
12+
for i in reversed(xrange(len(dp)-1)):
13+
dp[i] = max(dp[i+1], questions[i][0] + (dp[i+1+questions[i][1]] if i+1+questions[i][1] < len(dp) else 0))
14+
return dp[0]

0 commit comments

Comments
 (0)