static void Main(string[] args) { var t = new TreeNode(1); t.right = new TreeNode(2); t.right.right = new TreeNode(3); t.right.right.right = new TreeNode(4); MaxDepth(t); }
public static void Rec(TreeNode root) { if (root == null) { if (Max < Counter) { Max = Counter; } return; } Counter++; Rec(root.left); Rec(root.right); Counter--; }
public static int MaxDepth(TreeNode root) { Rec(root); return Max; }