using System.Collections;
public static void Main()
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
Console.WriteLine(isBalanced(root));
public static bool isBalanced(Node n)
if (n == null) return true;
if (Depth(n.left)-Depth(n.right) > 1)
return isBalanced(n.left) && isBalanced(n.right);
public static int Depth(Node n)
return 1 + Math.Max(Depth(n.left), Depth(n.right));
public Node right = null;