-
-
Save absognety/9785dfafd133d3841f0e159da90a5b96 to your computer and use it in GitHub Desktop.
Find the minimum path sum for binary tree (From root to leaf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find the minimum path sum (from root to leaf) | |
public static int minPathSum(TreeNode root) { | |
if(root == null) return 0; | |
int sum = root.val; | |
int leftSum = minPathSum(root.left); | |
int rightSum = minPathSum(root.right); | |
if(leftSum < rightSum){ | |
sum += leftSum; | |
}else{ | |
sum += rightSum; | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment