C# solution, beats 95% of c# submissions


  • 0
    F
    public class Solution {
        public IList<int> GetRow(int rowIndex) {
            if(rowIndex==0) return new List<int>{1};
            if(rowIndex==1) return new List<int>{1,1};
            var li = new List<int>();
            var pre=GetRow(rowIndex-1);
            for(int i= 0;i<=rowIndex;i++){
                if(i==0) li.Add(1);
                else if(i==rowIndex) li.Add(1);
                else{
                    
                    li.Add(pre.ElementAt(i-1)+pre.ElementAt(i));
                }
            }
            return li;
        }
    }
    

  • 0
    Y

    are you sure this solution use space O(k)? because you are using recursive....


Log in to reply
 

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