MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / findDiameter

Method findDiameter

TreeDiameter.java:11–18  ·  view source on GitHub ↗
(TreeNode root, int maxi[])

Source from the content-addressed store, hash-verified

9
10 }
11 public int findDiameter(TreeNode root, int maxi[])
12 {
13 if(root == null) return 0;
14 int left = findDiameter(root.left,maxi);
15 int right = findDiameter(root.right,maxi);
16 maxi[0]=Math.max(maxi[0],left+right);
17 return 1+Math.max(left,right);
18}
19}

Callers 1

diameterOfBinaryTreeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected