为避免版权问题不贴具体题目了
给两个暗号
496 单调栈
def tempreture(list): stack = [] res = [] n = len(list) for i in range(n-1, -1, -1): while stack and list[i] <= list[stack[-1]]: stack.pop() if not stack: res.append(0) else: res.append(stack[-1]-i) stack.append(i) return res[::-1] if __name__ == '__main__': line = input().strip().split(",") list = [int(x) for x in line] res = tempreture(list) toprint = [str(x) for x in res] print(",".join(toprint))
312 dp
class Solution: def maxCoins(self , nums ): # write code here nums.insert(0, 1) nums.append(1) n = len(nums) dp = [[0] * n for _ in range(n)] for i in range(n-1,-1,-1): for j in range(i, n): # TODO return dp[0][-1]
改代码的时候这边本地没改 直接改在网页里提交掉了 本地只有这个代码
全部评论
(2) 回帖