摘要:给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。 来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/subtree-of
阅读全文
摘要:给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。 注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 来源:力扣(LeetCode)链接:https://leetcode-c
阅读全文
摘要:class Solution: def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': if not root or root==p or root==q:return
阅读全文
摘要:class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: d={} for i ,x in enumerate(nums): another_num=target-x if another_num in
阅读全文