Skip to content

Commit

Permalink
Merge pull request #5 from hanhaotian/master
Browse files Browse the repository at this point in the history
update Solution
  • Loading branch information
HuberTRoy authored Aug 11, 2019
2 parents 0bc0920 + 6502189 commit fb72abf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
10 changes: 10 additions & 0 deletions BFS/MaximumDepthOfBinaryTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

36 changes: 15 additions & 21 deletions Tree/KthSmallestElementInABST.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit fb72abf

Please sign in to comment.