会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
月为暮
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
6
7
8
9
10
11
12
13
14
···
16
下一页
2020年7月1日
112买卖股票的最佳时机II
摘要: from typing import List# 这道题和上一题很类似,但有一些不同,每天都可以买入,或者卖出# 那么利润最大化,就是i + 1 天的价格比i天的价格高的时候买入# 然后在i + 1天卖出class Solution: def maxProfit(self, prices: List
阅读全文
posted @ 2020-07-01 16:40 月为暮
阅读(239)
评论(0)
推荐(0)
2020年6月30日
121.买卖股票的最佳时机
摘要: from typing import Listclass Solution: # 错误的思路,会超时。 def maxProfit1(self, prices: List[int]) -> int: if len(prices) <= 1:return 0 # 小于等于一天没法交易买和卖 # 进行双
阅读全文
posted @ 2020-06-30 18:25 月为暮
阅读(253)
评论(0)
推荐(0)
120三角形最小路径之和
摘要: 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 月为暮
阅读(259)
评论(0)
推荐(0)
119.杨辉三角II
摘要: 这道题和第118题是一样的,需要注意这道题目对行数的要求 # 定义一个列表,用来存放数据 num_list = [] for index1 in range(rowIndex + 1): # 每一行要先添加一个空列表 num_list.append([]) # 注意这里的for循环的范围 for i
阅读全文
posted @ 2020-06-30 16:20 月为暮
阅读(190)
评论(0)
推荐(0)
118.杨辉三角
摘要: 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 月为暮
阅读(236)
评论(0)
推荐(0)
117.填充每个节点的下一个右侧节点指针II
摘要: # 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 月为暮
阅读(211)
评论(0)
推荐(0)
2020年6月29日
116填充每个节点的下一个右侧节点指针
摘要: 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 月为暮
阅读(340)
评论(0)
推荐(0)
115不同的子序列
摘要: # 看着大佬的题解做了出来,但写不出来题解 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 月为暮
阅读(219)
评论(0)
推荐(0)
2020年6月20日
114.二叉树展开为链表
摘要: 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 月为暮
阅读(531)
评论(0)
推荐(0)
2020年6月16日
113路径总和II
摘要: 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 月为暮
阅读(183)
评论(0)
推荐(0)
上一页
1
···
6
7
8
9
10
11
12
13
14
···
16
下一页
公告