Easy recursive Java Sol

  • 0
        List<List<Integer>> toRet;
        public List<List<Integer>> findLeaves(TreeNode root) 
            toRet = new ArrayList<List<Integer>>();
            return toRet;
        int recMeth(TreeNode root)
            if(root == null)
                return -1;
            int l = recMeth(root.left);
            int r = recMeth(root.right);
            int ind = Math.max(l, r) + 1;
            if(toRet.size() <= ind)
                toRet.add(new ArrayList<Integer>());
            return ind;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.