class TreeNode{
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public class BSTMinimumPathSum {
public static int minPathSum(TreeNode root) {
if (root == null) {
return 0;
}
if (root.left != null && root.right == null) {
return root.val + minPathSum(root.left);
}
else if (root.left == null && root.right != null) {
return root.val + minPathSum(root.right);
}
else {
return root.val + Math.min(minPathSum(root.left), minPathSum(root.right));
}
}
}