C# Solution


  • 0
    M
    public IList<IList<int>> Generate(int numRows) {
        IList<IList<int>> list = new List<IList<int>>();
        
        for (int i = 0; i < numRows; i++)
        {
            IList<int> local = new List<int>(); 
            for (int j = 0; j <= i; j++)
            {
                if (j == 0 || j == i)
                {
                    local.Add(1);    
                }
                else 
                {
                    int val = list[i-1][j-1] + list[i-1][j];
                    local.Add(val);
                }
            }
            
            list.Add(local);
        }
        
        return list; 
    }

Log in to reply
 

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