[置顶] ACM刷题记录

摘要: P1056 [NOIP2008 普及组] 排座椅(排序) #include <stdio.h> #include <algorithm> using namespace std; typedef struct Line { int tag, cnt, idx; Line() {} Line(int 阅读全文

posted @ 2023-04-18 21:22 solvit 阅读(16) 评论(0) 推荐(0) 编辑

[置顶] LeetCode刷题记录

摘要: 贪心算法 LeetCode3 无重复字符的最长子串 LeetCode31 下一个排列 LeetCode53 最大子数组和 LeetCode55 跳跃游戏 LeetCode121 买卖股票的最佳时机 LeetCode122 买卖股票的最佳时机 II LeetCode123 买卖股票的最佳时机 III 阅读全文

posted @ 2022-06-29 10:36 solvit 阅读(31) 评论(0) 推荐(0) 编辑

2022年9月30日

LeetCode剑指 Offer II 093 最长斐波那契数列

摘要: LeetCode剑指 Offer II 093 最长斐波那契数列 class Solution: def lenLongestFibSubseq(self, arr: List[int]) -> int: n, loc, ans = len(arr), {}, 0 for i in range(n) 阅读全文

posted @ 2022-09-30 17:12 solvit 阅读(20) 评论(0) 推荐(0) 编辑

2022年9月26日

LeetCode554 砖墙

摘要: LeetCode554 砖墙 哈希 class Solution: def leastBricks(self, wall: List[List[int]]) -> int: wall_len, cnt, m = sum(wall[0]), {}, len(wall) for i in range(m 阅读全文

posted @ 2022-09-26 21:58 solvit 阅读(20) 评论(0) 推荐(0) 编辑

LeetCode739 每日温度

摘要: LeetCode739 每日温度 class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: ans, stack, n = [0] * len(temperatures), [], len(t 阅读全文

posted @ 2022-09-26 21:32 solvit 阅读(17) 评论(0) 推荐(0) 编辑

2022年9月25日

LeetCode2096 从二叉树一个节点到另一个节点每一步的方向

摘要: LeetCode2096 从二叉树一个节点到另一个节点每一步的方向 最近公共祖先的变形题. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None 阅读全文

posted @ 2022-09-25 17:23 solvit 阅读(16) 评论(0) 推荐(0) 编辑

2022年9月24日

LeetCode740 删除并获得点数

摘要: LeetCode740 删除并获得点数 LeetCode198 打家劫舍的变形题目 class Solution: def deleteAndEarn(self, nums: List[int]) -> int: maxVal = max(nums) total = [0] * (maxVal + 阅读全文

posted @ 2022-09-24 13:28 solvit 阅读(10) 评论(0) 推荐(0) 编辑

2022年9月23日

LeetCode剑指 Offer II 097 子序列的数目

摘要: LeetCode剑指 Offer II 097 子序列的数目 $f[i][j]$ 表示 $s[:i]$ 包含 $t[:j]$ 子序列的个数 $s[i] == t[i]$ 时, $f[i][j] = f[i - 1][j - 1] + f[i - 1][j]$, 当前 $s[i]$ 用或者不用 $s[ 阅读全文

posted @ 2022-09-23 15:38 solvit 阅读(21) 评论(0) 推荐(0) 编辑

LeetCode1235 规划兼职工作

摘要: LeetCode1235 规划兼职工作 按照结束时间进行排序 $f[i]$表示前$i$个工作的最大报酬, 第$i$个工作可选可不选 第$i$个不拿: $f[i] = max(f[i], f[i - 1])$ 第$i$个拿: $f[i] = max(f[i], f[j] + profit[i])$, 阅读全文

posted @ 2022-09-23 00:39 solvit 阅读(13) 评论(0) 推荐(0) 编辑

2022年9月2日

LeetCode617 合并二叉树

摘要: LeetCode617 合并二叉树 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.l 阅读全文

posted @ 2022-09-02 23:11 solvit 阅读(12) 评论(0) 推荐(0) 编辑

2022年8月24日

LeetCode338 比特位计数

摘要: LeetCode338 比特位计数 class Solution: def countBits(self, n: int) -> List[int]: def cnt(x: int) -> int: ones = 0 while x > 0: x = x & (x - 1) ones = ones 阅读全文

posted @ 2022-08-24 16:56 solvit 阅读(12) 评论(0) 推荐(0) 编辑

导航