From 8ff1f8762820e5997bfecd765a21e31366f82cb3 Mon Sep 17 00:00:00 2001 From: hanhaotian Date: Thu, 8 Aug 2019 20:01:36 +0800 Subject: [PATCH 1/2] update Solution --- BFS/MaximumDepthOfBinaryTree.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BFS/MaximumDepthOfBinaryTree.py b/BFS/MaximumDepthOfBinaryTree.py index 985c446..6398496 100644 --- a/BFS/MaximumDepthOfBinaryTree.py +++ b/BFS/MaximumDepthOfBinaryTree.py @@ -28,3 +28,13 @@ https://leetcode.com/problems/maximum-depth-of-binary-tree/description/ """ +class Solution: + + def maxDepth(self, root: TreeNode) -> int: + if root is None: + return 0 + else: + left_height = self.maxDepth(root.left) + right_height = self.maxDepth(root.right) + return max(left_height, right_height) + 1 + From 65021893f1c962bf31f5028518eef5c87e92215b Mon Sep 17 00:00:00 2001 From: hanhaotian Date: Thu, 8 Aug 2019 20:06:35 +0800 Subject: [PATCH 2/2] Update KthSmallestElementInABST.py --- Tree/KthSmallestElementInABST.py | 36 +++++++++++++------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/Tree/KthSmallestElementInABST.py b/Tree/KthSmallestElementInABST.py index c273307..c2058e1 100644 --- a/Tree/KthSmallestElementInABST.py +++ b/Tree/KthSmallestElementInABST.py @@ -56,24 +56,18 @@ # self.left = None # self.right = None -class Solution(object): - def kthSmallest(self, root, k): - """ - :type root: TreeNode - :type k: int - :rtype: int - """ - self.inorder_result = [] - - def inorder(root): - if root.left: - inorder(root.left) - - self.inorder_result.append(root.val) - - if root.right: - inorder(root.right) - - inorder(root) - - return self.inorder_result[k-1] +class Solution: + + def find_data(self, root: TreeNode): + + if root is None: + return + Solution.find_data(self,root.left) + self.data.append(root.val) + Solution.find_data(self,root.right) + return + + def kthSmallest(self, root: TreeNode, k: int) -> int: + self.data = [] + Solution.find_data(self, root) + return self.data[k-1]