上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页

2022年6月29日

LeetCode319 灯泡开关

摘要: LeetCode319 灯泡开关 等价于求小于等于n的平方数的个数 class Solution: def bulbSwitch(self, n: int) -> int: if n == 0: return 0 i, ans = 1, 0 while i * i <= n: ans, i = an 阅读全文

posted @ 2022-06-29 20:03 solvit 阅读(15) 评论(0) 推荐(0)

LeetCode233 数字 1 的个数

摘要: LeetCode233 数字 1 的个数 枚举每一个数位为1时存在多少种满足小于等于n的数字 当前数位大于1,不存在限制,存在数字个数为左边 $\times$ 右边 当前数位等于1,右边存在限制,当左边等于n的部分时,右边必须满足小于等于n的条件 当前数位等于0,右边存在限制,当左边等于n的部分时, 阅读全文

posted @ 2022-06-29 19:30 solvit 阅读(27) 评论(0) 推荐(0)

LeetCode188 买卖股票的最佳时机 IV(dp)

摘要: LeetCode188 买卖股票的最佳时机 IV 对于第 $i$ 只股票,可以进行的操作为作为第 $j$ 只买入或卖出的股票 $buy[i][j]$ 表示对于前 $i$ 只股票,第 $j$ 次买入股票之后的最大收益 $sell[i][j]$ 表示对于前 $i$ 只股票,第 $j$ 次卖出股票之后的最 阅读全文

posted @ 2022-06-29 16:16 solvit 阅读(30) 评论(0) 推荐(0)

LeetCode123 买卖股票的最佳时机 III(贪心)

摘要: LeetCode123 买卖股票的最佳时机 III 最多可以完成两笔交易,即分两段做LeetCode121,处理前缀后缀之后,遍历每一个分段节点所带来的收益取最大 class Solution: def maxProfit(self, prices: List[int]) -> int: pre_g 阅读全文

posted @ 2022-06-29 14:31 solvit 阅读(31) 评论(0) 推荐(0)

LeetCode122 买卖股票的最佳时机 II(贪心)

摘要: LeetCode122 买卖股票的最佳时机 II 贪心计算爬峰收益 class Solution: def maxProfit(self, prices: List[int]) -> int: ans, l = 0, len(prices) for i in range(1, l): ans += 阅读全文

posted @ 2022-06-29 13:29 solvit 阅读(21) 评论(0) 推荐(0)

LeetCode121 买卖股票的最佳时机(贪心)

摘要: LeetCode121 买卖股票的最佳时机 维护当前股票价格最小值 class Solution: def maxProfit(self, prices: List[int]) -> int: ans, cur_min, l = 0, prices[0], len(prices) for i in 阅读全文

posted @ 2022-06-29 13:08 solvit 阅读(21) 评论(0) 推荐(0)

LeetCode124 二叉树中的最大路径和(dfs)

摘要: LeetCode124 二叉树中的最大路径和 dfs左右子节点的最大收益 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self 阅读全文

posted @ 2022-06-29 12:54 solvit 阅读(30) 评论(0) 推荐(0)

LeetCode115 不同的子序列(dp)

摘要: LeetCode115 不同的子序列 $dp[i][j]$ 表示字符串 $s[:i]$ 中包子序列 $t[:j]$ 的数量 对于当前字符 $s[i]$ 与 $t[j]$: 如果 $s[i] == t[j]$,$dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]$ 如 阅读全文

posted @ 2022-06-29 12:35 solvit 阅读(28) 评论(0) 推荐(0)

LeetCode69 x的平方根 (二分)

摘要: LeetCode69 x的平方根 class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ l, r, ans = 0, x, -1 while l <= r: mid = (l + r) // 2 i 阅读全文

posted @ 2022-06-29 11:00 solvit 阅读(19) 评论(0) 推荐(0)

LeetCode72 编辑距离(dp)

摘要: LeetCode72 编辑距离 对单词A删除一个等价于对单词B插入一个字符,基于此我们仅考虑如下三种操作: 对单词A插入一个字符 对单词B插入一个字符 对单词A替换一个字符 class Solution(object): def minDistance(self, word1, word2): "" 阅读全文

posted @ 2022-06-29 10:50 solvit 阅读(29) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页

导航