I have a binary search tree and I want to find the minimum path sum from root to leaf, below is my recursion solution
public int Solution(TreeNode root) {
if (root == null) return 0;
if (root.left != null && root.right == null)
return Solution(root.left) + root.val;
if (root.left == null && root.right != null)
return Solution(root.right) + root.val;
return Math.min(Solution(root.left), Solution(root.right)) + root.val;
}
Question #1:
Is this solution Depth First Search because it first goes through to the deepest place of the left subtree (I assume).
Question #2:
What is the time complexity and space complexity of this method?