标签:nbsp com 获得 span bsp tin lse for value
class Solution: def maxValue(self, grid: List[List[int]]) -> int: for i in range(len(grid)): for j in range(len(grid[0])): if i == 0 and j == 0: continue elif i == 0: grid[i][j] += grid[i][j-1] elif j == 0: grid[i][j] += grid[i-1][j] else: grid[i][j] += max(grid[i-1][j],grid[i][j-1]) return grid[-1][-1]
class Solution: def maxValue(self, grid: List[List[int]]) -> int: if not grid or not grid[0]: return 0 m, n = len(grid), len(grid[0]) for i in range(1, n): grid[0][i] += grid[0][i-1] for i in range(1, m): grid[i][0] += grid[i-1][0] for j in range(1,n): grid[i][j] += max(grid[i-1][j], grid[i][j-1]) return grid[-1][-1] 作者:luanz 链接:https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/solution/pythonchang-gui-dong-gui-jie-fa-jian-dan-yi-dong-b/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
标签:nbsp com 获得 span bsp tin lse for value
原文地址:https://www.cnblogs.com/topass123/p/12635832.html