上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 51 下一页
摘要: 类似题目参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # 先特判: # 当节点root为空时:return None; # 当p或q的值域等于root时,return root; # 再递归判 阅读全文
posted @ 2020-09-13 15:25 人间烟火地三鲜 阅读(103) 评论(0) 推荐(0)
摘要: 方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # BFS def kthSmallest(self, root, k): """ :type 阅读全文
posted @ 2020-09-13 15:20 人间烟火地三鲜 阅读(137) 评论(0) 推荐(0)
摘要: BFS模板的应用 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): def connect(self, root): """ :type root: Node :rtype 阅读全文
posted @ 2020-09-13 15:15 人间烟火地三鲜 阅读(131) 评论(0) 推荐(0)
摘要: 输入: {"$id":"1","left":{"$id":"2","left":{"$id":"3","left":null,"next":null,"right":null,"val":4},"next":null,"right":{"$id":"4","left&q 阅读全文
posted @ 2020-09-13 15:12 人间烟火地三鲜 阅读(108) 评论(0) 推荐(0)
摘要: BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): def minDepth(self, root): """ :type root: TreeNode 阅读全文
posted @ 2020-09-13 15:03 人间烟火地三鲜 阅读(167) 评论(0) 推荐(0)
摘要: class Solution(object): # 题意要转成平衡二叉搜索树 # 先转成list,在转BST呗。 def sortedListToBST(self, head): """ :type head: ListNode :rtype: TreeNode """ if not head: r 阅读全文
posted @ 2020-09-13 14:51 人间烟火地三鲜 阅读(142) 评论(0) 推荐(0)
摘要: 方法一:递归 class Solution(object): # 递归思路: # 当p,q都在root的右子树中时,递归root.right并返回; # 当p,q都在root的左子树中时,递归root.left并返回; # 返回值:最近公共祖先root。 def lowestCommonAncest 阅读全文
posted @ 2020-08-30 17:59 人间烟火地三鲜 阅读(295) 评论(0) 推荐(0)
摘要: # Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self.next = None # Definition for a binary tree node. 阅读全文
posted @ 2020-08-30 17:54 人间烟火地三鲜 阅读(180) 评论(0) 推荐(0)
摘要: class Solution(object): def constructMaximumBinaryTree(self, nums): """ :type nums: List[int] :rtype: TreeNode """ if not nums: return rootval = max(n 阅读全文
posted @ 2020-08-30 17:47 人间烟火地三鲜 阅读(153) 评论(0) 推荐(0)
摘要: # Definition for a Node. class Node(object): def __init__(self, val=None, children=None): self.val = val self.children = children 方法一:迭代 class Solutio 阅读全文
posted @ 2020-08-30 17:23 人间烟火地三鲜 阅读(142) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 51 下一页