Skip to content

Commit

Permalink
Day 102
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagannath8 authored Apr 12, 2024
1 parent 1ff2bea commit 9ccdf3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
42 changes: 42 additions & 0 deletions Path Sum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Definition for binary tree
* class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) {
* val = x;
* left=null;
* right=null;
* }
* }
*/
public class Solution {
public static boolean flag = false;
public int hasPathSum(TreeNode A, int B) {
flag = false;
int sum = 0;
if (A == null)
return 0;
if ( A != null && A.left == null && A.right == null && A.val == B)
return 1;

sum += A.val;
hasPathSumUtil(A,B,sum);
return flag == true ? 1 : 0;
}

public void hasPathSumUtil(TreeNode A, int B, int sum) {
if (flag == true)
return;
if (A.left == null && A.right == null){
if (B == sum)
flag = true;
return ;
}
if (A.left != null)
hasPathSumUtil(A.left, B,sum + A.left.val);
if (A.right != null)
hasPathSumUtil(A.right, B,sum + A.right.val);
}
}
22 changes: 0 additions & 22 deletions Trapping Rain Water.java

This file was deleted.

0 comments on commit 9ccdf3f

Please sign in to comment.