Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Boolean state = false;
- static Boolean path_sum(BinaryTreeNode root, Integer k) {
- path_sum_helper(root, k);
- return state;
- }
- static void path_sum_helper(BinaryTreeNode root, Integer target) {
- if (root.left == null && root.right == null) {
- if (target.equals(root.value)) {
- state = true;
- return;
- }
- }
- if (root.left != null) {
- path_sum_helper(root.left, target - root.value);
- }
- if (state == true) {
- return;
- }
- if (root.right != null) {
- path_sum_helper(root.right, target - root.value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement