上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 47 下一页
摘要: 题目描述: 方法一:迭代 class Solution: def flatten(self, root: TreeNode) -> None: """ Do not return anything, modify root in-place instead. """ cur = root while 阅读全文
posted @ 2019-07-14 20:19 oldby 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 恢复内容开始 题目描述: 方法一:O(n) O(n) class Solution: def sortedListToBST(self, head: ListNode) -> TreeNode: nums = [] while head: nums.append(head.val) head = h 阅读全文
posted @ 2019-07-14 19:42 oldby 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:O(n) O(n) class Solution: def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: assert len(inorder)==len(postorder) if 阅读全文
posted @ 2019-07-14 17:31 oldby 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class 阅读全文
posted @ 2019-07-14 17:20 oldby 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class 阅读全文
posted @ 2019-07-14 15:21 oldby 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归O(n) O(n) # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = 阅读全文
posted @ 2019-07-14 14:37 oldby 阅读(461) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None cla 阅读全文
posted @ 2019-07-14 11:45 oldby 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:动态规划 O(n^2) O(n) class Solution: def numTrees(self, n: int) -> int: dp = [0]*(n+1) dp[0],dp[1] = 1,1 for i in range(2,n+1): for j in range(1 阅读全文
posted @ 2019-07-14 11:11 oldby 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归 class Solution: def postorderTraversal(self, root: TreeNode) -> List[int]: res = [] def helper(root): if not root: return helper(root.lef 阅读全文
posted @ 2019-07-13 19:55 oldby 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 恢复内容开始 题目描述: 方法一:递归 class Solution: def preorderTraversal(self, root: TreeNode) -> List[int]: res = [] def helper(root): if not root: return res.appen 阅读全文
posted @ 2019-07-13 18:57 oldby 阅读(160) 评论(0) 推荐(0) 编辑
上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 47 下一页