From c1c4395852cb1ef8e3350798f3762588cfbfda2f Mon Sep 17 00:00:00 2001 From: Debsishu Pal <61660793+debsishu@users.noreply.github.com> Date: Sun, 3 Jan 2021 02:10:25 +0530 Subject: [PATCH] Update DiameterOfTree.java Updated the calculation of the diameter where it passes through the root --- src/chapter06trees/DiameterOfTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chapter06trees/DiameterOfTree.java b/src/chapter06trees/DiameterOfTree.java index d6f5fd9..4ae8015 100644 --- a/src/chapter06trees/DiameterOfTree.java +++ b/src/chapter06trees/DiameterOfTree.java @@ -32,7 +32,7 @@ public int diameter(BinaryTreeNode root){ if(root==null) return 0; //the path goes through the root - int len1 = height(root.left) + height(root.right) +3; + int len1 = height(root.left) + height(root.right) + 1; //the path does not pass the root int len2 = Math.max(diameter(root.left), diameter(root.right));