上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页
摘要: from typing import List# 这道题和上一题很类似,但有一些不同,每天都可以买入,或者卖出# 那么利润最大化,就是i + 1 天的价格比i天的价格高的时候买入# 然后在i + 1天卖出class Solution: def maxProfit(self, prices: List 阅读全文
posted @ 2020-07-01 16:40 月为暮 阅读(230) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: # 错误的思路,会超时。 def maxProfit1(self, prices: List[int]) -> int: if len(prices) <= 1:return 0 # 小于等于一天没法交易买和卖 # 进行双 阅读全文
posted @ 2020-06-30 18:25 月为暮 阅读(248) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: def minimumTotal1(self, triangle: List[List[int]]) -> int: return self.dfs(triangle,0,0,len(triangle),0) # 深搜的做 阅读全文
posted @ 2020-06-30 17:52 月为暮 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 这道题和第118题是一样的,需要注意这道题目对行数的要求 # 定义一个列表,用来存放数据 num_list = [] for index1 in range(rowIndex + 1): # 每一行要先添加一个空列表 num_list.append([]) # 注意这里的for循环的范围 for i 阅读全文
posted @ 2020-06-30 16:20 月为暮 阅读(186) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: def generate(self, numRows: int) -> List[List[int]]: # 定义一个列表,用来存放数据 num_list = [] for index1 in range(numRows) 阅读全文
posted @ 2020-06-30 16:15 月为暮 阅读(229) 评论(0) 推荐(0) 编辑
摘要: # Definition for a Node.class Node: def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None): self.val = val s 阅读全文
posted @ 2020-06-30 15:55 月为暮 阅读(205) 评论(0) 推荐(0) 编辑
摘要: class Node: def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None): self.val = val self.left = left self.rig 阅读全文
posted @ 2020-06-29 17:45 月为暮 阅读(334) 评论(0) 推荐(0) 编辑
摘要: # 看着大佬的题解做了出来,但写不出来题解 class Solution: def numDistinct(self,s:str,t:str) -> int: n1 = len(s) n2 = len(t) dp = [[0] * (n1 + 1) for _ in range((n2 + 1))] 阅读全文
posted @ 2020-06-29 17:41 月为暮 阅读(214) 评论(0) 推荐(0) 编辑
摘要: class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = rightclass Solution: def flatten(self, 阅读全文
posted @ 2020-06-20 20:12 月为暮 阅读(525) 评论(0) 推荐(0) 编辑
摘要: class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Nonea = TreeNode(1)b = TreeNode(2)c = TreeNode(3)a.left = ba.right = 阅读全文
posted @ 2020-06-16 21:39 月为暮 阅读(180) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页