diff --git a/InterviewBit/143968aa-0c2f-454e-8f04-721758d4bab8.jpg b/InterviewBit/143968aa-0c2f-454e-8f04-721758d4bab8.jpg new file mode 100644 index 0000000..03ba12d Binary files /dev/null and b/InterviewBit/143968aa-0c2f-454e-8f04-721758d4bab8.jpg differ diff --git a/InterviewBit/MAXDepthofBinaryTree.py b/InterviewBit/MAXDepthofBinaryTree.py new file mode 100644 index 0000000..a9d14db --- /dev/null +++ b/InterviewBit/MAXDepthofBinaryTree.py @@ -0,0 +1,14 @@ +# Definition for a binary tree node +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + # @param A : root node of tree + # @return an integer + def maxDepth(self, A): + if A is None: + return 0 + return max(self.maxDepth(A.left),self.maxDepth(A.right))+1 diff --git a/InterviewBit/MINDepthofBinaryTree.py b/InterviewBit/MINDepthofBinaryTree.py new file mode 100644 index 0000000..17f1283 --- /dev/null +++ b/InterviewBit/MINDepthofBinaryTree.py @@ -0,0 +1,24 @@ +# Definition for a binary tree node +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + # @param A : root node of tree + # @return an integer + def minDepth(self, A): + if A is None: + return 0 + + + if A.left==None and A.right==None: + return 1 + + if A.left==None: + return self.minDepth(A.right)+1 + if A.right==None: + return self.minDepth(A.left)+1 + return 1 + min(self.minDepth(A.left),self.minDepth(A.right)) + diff --git a/InterviewBit/Roottoleafpath.py b/InterviewBit/Roottoleafpath.py new file mode 100644 index 0000000..4a1efe1 --- /dev/null +++ b/InterviewBit/Roottoleafpath.py @@ -0,0 +1,18 @@ +class Solution: + # @param A : root node of tree + # @param B : integer + # @return a list of list of integers + def pathSum(self, A, B): + if A is None: + return [] + q=[[A,A.val,[A.val]]] + c=[] + while q: + a=q.pop(0) + if a[0].left==None and a[0].right==None and a[1]==B: + c.append(a[2]) + if a[0].left: + q.append([a[0].left,a[1]+a[0].left.val,a[2]+[a[0].left.val]]) + if a[0].right: + q.append([a[0].right,a[1]+a[0].right.val,a[2]+[a[0].right.val]]) + return c diff --git a/InterviewBit/cb3a05a9-ba05-42a4-98f1-f00ed1713c2e.jpg b/InterviewBit/cb3a05a9-ba05-42a4-98f1-f00ed1713c2e.jpg new file mode 100644 index 0000000..2f757e7 Binary files /dev/null and b/InterviewBit/cb3a05a9-ba05-42a4-98f1-f00ed1713c2e.jpg differ diff --git a/InterviewBit/de76e162-8a87-4789-883e-d24be476a580.jpg b/InterviewBit/de76e162-8a87-4789-883e-d24be476a580.jpg new file mode 100644 index 0000000..be8e627 Binary files /dev/null and b/InterviewBit/de76e162-8a87-4789-883e-d24be476a580.jpg differ