From 6c4123672c3ff32d12aef0fd5faab82210543f5e Mon Sep 17 00:00:00 2001 From: NOOBIE666 <129605338+NOOBE666@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:43:25 +0530 Subject: [PATCH] Update Node having sum of children and node is max.java Time Complexity is not that good but it works --- ...aving sum of children and node is max.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Lecture 10 : Trees/Node having sum of children and node is max.java b/Lecture 10 : Trees/Node having sum of children and node is max.java index 8295f35..4ec094f 100644 --- a/Lecture 10 : Trees/Node having sum of children and node is max.java +++ b/Lecture 10 : Trees/Node having sum of children and node is max.java @@ -32,7 +32,28 @@ public class Solution { public static TreeNode maxSumNode(TreeNode root){ - // Write your code here + if(root == null) + return null; + TreeNode temp=null; + Queue> q=new LinkedList<>(); + q.add(root); + int s=0; + while(!q.isEmpty()){ + int size=q.size(); + for(int i=0;itemp1=q.poll(); + int s1=temp1.data; + for(int j=0;js){ + s=s1; + temp=temp1; + } + } + } + return temp; }