Amazing explanation.. When I saw your video I checked my playback speed it was normal but I was feeling like it's in 1.5x is it you normal speed of saying?
Good attempt. But I could not understand what constitutes a "path." I watched many videos, except one or two, and none explained the problem and "solution" clearly.
I try avoiding global variables so I used an array of single element instead, you can also use global variable class Solution { public int solve(TreeNode root, int[] ans){ if(root == null) return 0; int left = solve(root.left,ans); int right = solve(root.right,ans); int st_path = Math.max(root.val,Math.max((root.val + left),(root.val + right))); int cur_path = root.val + left + right; ans[0] = Math.max(ans[0],Math.max(st_path,cur_path)); return st_path; } public int maxPathSum(TreeNode root) { int[] ans = new int[1]; ans[0] = Integer.MIN_VALUE; solve(root,ans); return ans[0]; } } This is the leetcode java code for problem : 124. Binary Tree Maximum Path Sum
public class Solution { int Solve(TreeNode A, int ans){ if(A == null) return 0; int left = Solve(A.left, ans); int right = Solve(A.right, ans); int straight = Math.max(A.val, Math.max(left + A.val, right + A.val)); int curved = A.val + left + right; ans = Math.max(ans, Math.max(straight, curved)); return straight;
} public int maxPathSum(TreeNode A) { int ans = Integer.MIN_VALUE; Solve(A, ans); return ans; } } Mam Can you tell error in this? It is giving error?
This is the BEST explanation for this question on you tube.❤
Wow thank you so much ....best explanation available on you tube for this question.
This is such a neat explanation!
Amazing explanation..
When I saw your video I checked my playback speed it was normal but I was feeling like it's in 1.5x is it you normal speed of saying?
hi
just loved the starting part where you said we are going to do a problem ans rhyming just made my day
best solution keep making more videos
Best explanation 👍
Excellent explanation
Great explanation . Deserve more subs
Crisp explanation 👏👏
thanks ,
mam your explanation is always best
crystal clear ...thanks ...short and crisp...
Good attempt. But I could not understand what constitutes a "path." I watched many videos, except one or two, and none explained the problem and "solution" clearly.
Alisha, in these tree questions, I am not able to think recursively and facing difficulty. I always get a wrong answer. What to do ?
Great Explanation. Please do provide Java Code solution if possible.
I try avoiding global variables so I used an array of single element instead, you can also use global variable
class Solution {
public int solve(TreeNode root, int[] ans){
if(root == null) return 0;
int left = solve(root.left,ans);
int right = solve(root.right,ans);
int st_path = Math.max(root.val,Math.max((root.val + left),(root.val + right)));
int cur_path = root.val + left + right;
ans[0] = Math.max(ans[0],Math.max(st_path,cur_path));
return st_path;
}
public int maxPathSum(TreeNode root) {
int[] ans = new int[1];
ans[0] = Integer.MIN_VALUE;
solve(root,ans);
return ans[0];
}
}
This is the leetcode java code for problem : 124. Binary Tree Maximum Path Sum
public class Solution {
int Solve(TreeNode A, int ans){
if(A == null) return 0;
int left = Solve(A.left, ans);
int right = Solve(A.right, ans);
int straight = Math.max(A.val, Math.max(left + A.val, right + A.val));
int curved = A.val + left + right;
ans = Math.max(ans, Math.max(straight, curved));
return straight;
}
public int maxPathSum(TreeNode A) {
int ans = Integer.MIN_VALUE;
Solve(A, ans);
return ans;
}
}
Mam Can you tell error in this? It is giving error?
Either make the ans variable global or use an array of size 1 to store ans if you want to solve like this. You cannot do like this in Java
You solved this problem in your previous videos
Gr*