Exemplo n.º 1
0
        private void TraverseInOrder(TreeNode root, List <int> nums)
        {
            if (root == null)
            {
                return;
            }

            TraverseInOrder(root.left, nums);
            nums.Add(root.val);
            TraverseInOrder(root.right, nums);
        }
Exemplo n.º 2
0
        private int DFS(TreeNode current)
        {
            if (current == null)
            {
                return(0);
            }

            var left  = DFS(current.left) + 1;
            var right = DFS(current.right) + 1;

            return(Math.Max(left, right));
        }