public IList<IList<int>> Excution1(IsSameTree.TreeNode root)
 {
     var result = new List<IList<int>>();
     ExcutionPrivate(root, result, 0);
     result.Reverse();
     return result;
 }
Beispiel #2
0
 public int Excution1(IsSameTree.TreeNode root)
 {
     if (root == null)
     {
         return(0);
     }
     return(1 + Math.Max(Excution1(root.left), Excution1(root.right)));
 }
        private void ExcutionPrivate(IsSameTree.TreeNode root, List<IList<int>> list, int level)
        {
            if (root == null) return;

            while (list.Count <= level)
            {
                list.Add(new List<int>());
            }

            list[level].Add(root.val);

            level++;
            ExcutionPrivate(root.left, list, level);
            ExcutionPrivate(root.right, list, level);
        }