C# easy to understand code


  • 0
    Y
    public class Solution {
        public IList<int> LargestValues(TreeNode root) {        
            List<int> ret = new List<int>();
            if(root==null)
                return ret;
            
            getLevelTree(root, 0, ret);        
            return ret;
        }
        
        void getLevelTree(TreeNode root, int level, List<int> ret){
            if(root==null)
                return;
            
            if(level == ret.Count)
                ret.Add(int.MinValue);
            
            if(ret[level] < root.val )
                ret[level]=root.val;    
            
            getLevelTree(root.left, level + 1, ret);
            getLevelTree(root.right, level + 1, ret);        
        }
    

Log in to reply
 

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