my 11 line java code above 93%


  • 0
    public List<Integer> largestValues(TreeNode root) {
            List<Integer> list = new ArrayList<>();
            find(root,list,0);
            return list;
        }
        public void find(TreeNode root,List<Integer> list,int level) {
            if(root == null) return;
            if(list.size() == level) list.add(root.val);
            else list.set(level,Math.max(root.val,list.get(level)) );
            find(root.left,list,level + 1);
            find(root.right,list,level + 1);
        }

Log in to reply
 

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