Esempio n. 1
0
        private static int Helper(LeetCode366TreeNode root)
        {
            if (root == null)
            {
                return(-1);
            }

            var left  = Helper(root.left);
            var right = Helper(root.right);

            var curr = Math.Max(left, right) + 1;

            if (ans.Count == curr)
            {
                ans.Add(new List <int>());
            }

            ans[curr].Add(root.val);

            return(curr);
        }
Esempio n. 2
0
 public static IList <IList <int> > FindLeaves(LeetCode366TreeNode root)
 {
     Helper(root);
     return(ans);
 }
Esempio n. 3
0
 public LeetCode366TreeNode(int val = 0, LeetCode366TreeNode left = null, LeetCode366TreeNode right = null)
 {
     this.val   = val;
     this.left  = left;
     this.right = right;
 }