Python Clean Solution O(N*N*K)


  • 0
    class Solution(object):
        def maxVacationDays(self, flights, days):
            """
            :type flights: List[List[int]]
            :type days: List[List[int]]
            :rtype: int
            """
            dp = [[float("-inf")] * len(flights) for _ in range(len(days[0]) + 1)]
            dp[0][0] = 0
            for i in range(len(days[0])):
                for j in range(len(flights)):
                    for k in range(len(flights)):
                        if flights[k][j] == 1 or j == k:
                            dp[i+1][j] = max(dp[i+1][j], dp[i][k] + days[j][i])
            return max(dp[-1])
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.