fork download
  1. /*
  2.  
  3. Following is the structure used to represent the Binary Tree Node
  4.  
  5. class BinaryTreeNode<T> {
  6. T data;
  7. BinaryTreeNode<T> left;
  8. BinaryTreeNode<T> right;
  9.  
  10. public BinaryTreeNode(T data) {
  11. this.data = data;
  12. this.left = null;
  13. this.right = null;
  14. }
  15. }
  16.  
  17. */
  18.  
  19. public class Solution {
  20.  
  21. public static int height(BinaryTreeNode<Integer> node) {
  22.  
  23. if (node == null)
  24. return 0;
  25.  
  26. return Math.max(height(node.left), height(node.right)) + 1;
  27. }
  28.  
  29.  
  30. public static int diameterOfBinaryTree(BinaryTreeNode<Integer> root){
  31.  
  32. if (root == null)
  33. return 0;
  34.  
  35. int opt1 = height(root.left) + height(root.right) + 1;
  36.  
  37. int opt2 = diameterOfBinaryTree(root.left);
  38.  
  39. int opt3 = diameterOfBinaryTree(root.right);
  40.  
  41. return Math.max(opt1, Math.max(opt2, opt3));
  42. }
  43.  
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:19: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
Main.java:21: error: cannot find symbol
	public static int height(BinaryTreeNode<Integer> node) {
	                         ^
  symbol:   class BinaryTreeNode
  location: class Solution
Main.java:30: error: cannot find symbol
	public static int diameterOfBinaryTree(BinaryTreeNode<Integer> root){
	                                       ^
  symbol:   class BinaryTreeNode
  location: class Solution
3 errors
stdout
Standard output is empty