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

2022年7月3日

LeetCode673 最长递增子序列的个数

摘要: LeetCode673 最长递增子序列的个数 贪心 + 前缀和 + 二分查找 $q[i][]$ 数组表示所有能成为长度为 $i$ 的最长上升子序列的末尾元素的值 $cnt[i][j]$ 记录以 $q[i][j]$ 为结尾的最长上升子序列的个数 参考 class Solution: def findN 阅读全文

posted @ 2022-07-03 15:54 solvit 阅读(27) 评论(0) 推荐(0)

LeetCode560 和为 K 的子数组

摘要: LeetCode560 和为 K 的子数组 前缀和 + 哈希 class Solution: def subarraySum(self, nums: List[int], k: int) -> int: pre_count, pre, ans = {}, 0, 0 pre_count[0] = 1 阅读全文

posted @ 2022-07-03 13:44 solvit 阅读(25) 评论(0) 推荐(0)

2022年7月2日

LeetCode236 二叉树的最近公共祖先

摘要: LeetCode236 二叉树的最近公共祖先 dfs二叉树,记录以当前节点为根节点的子树是否包含p节点或q节点 记录第一次满足条件的节点即为所求最近公共祖先 判断条件为:1. 左右子树分别含有p节点和q节点;2. 当前节点为p节点或q节点,另一节点在左子树或右子树中. # Definition fo 阅读全文

posted @ 2022-07-02 16:28 solvit 阅读(25) 评论(0) 推荐(0)

LeetCode103 二叉树的锯齿形层序遍历

摘要: LeetCode103 二叉树的锯齿形层序遍历 使用两个栈进行模拟 + bfs # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # s 阅读全文

posted @ 2022-07-02 14:47 solvit 阅读(26) 评论(0) 推荐(0)

LeetCode33 搜索旋转排序数组(二分)

摘要: LeetCode33 搜索旋转排序数组 二分数列,仅仅当对于当前处理部分nums[l] < target < nums[r]时,进行答案更新,否则在另一部分寻找答案 class Solution: def search(self, nums: List[int], target: int) -> i 阅读全文

posted @ 2022-07-02 14:35 solvit 阅读(26) 评论(0) 推荐(0)

LeetCode386 字典序排数

摘要: LeetCode386 字典序排数 构造字典树,dfs遍历记录 class Solution: def lexicalOrder(self, n: int) -> List[int]: ans = [] def dfs(cur): if cur <= n: ans.append(cur) else: 阅读全文

posted @ 2022-07-02 14:17 solvit 阅读(24) 评论(0) 推荐(0)

2022年7月1日

LeetCode287 寻找重复数(快慢指针寻找环入口)

摘要: LeetCode287 寻找重复数 快慢指针寻找环入口 关于判定有环之后如果寻找环入口可参考 参考 class Solution: def findDuplicate(self, nums: List[int]) -> int: slow, fast = nums[0], nums[nums[0]] 阅读全文

posted @ 2022-07-01 22:47 solvit 阅读(27) 评论(0) 推荐(0)

LeetCode846 一手顺子

摘要: LeetCode846 一手顺子 哈希算法,count字典记录每个元素出现个数,然后按顺子规则逐个消减,判定是否符合 class Solution: def isNStraightHand(self, hand: List[int], groupSize: int) -> bool: count, 阅读全文

posted @ 2022-07-01 22:02 solvit 阅读(27) 评论(0) 推荐(0)

LeetCode面试题 04.06. 后继者

摘要: LeetCode面试题 04.06. 后继者 求中序遍历中给定节点的后一个节点,分右子树中/父节点中 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # se 阅读全文

posted @ 2022-07-01 18:49 solvit 阅读(24) 评论(0) 推荐(0)

LeetCode337 打家劫舍 III

摘要: LeetCode337 打家劫舍 III 与LeetCode198 打家劫舍一致,将数列换为树形结构 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right 阅读全文

posted @ 2022-07-01 17:10 solvit 阅读(22) 评论(0) 推荐(0)

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

导航