C# solution


  • 0
    K
    public class Solution {
        public IList<IList<int>> Generate(int numRows) {
            
            IList<IList<int>> list = new List<IList<int>>();
            
            if (numRows > 0)
            {
                for (int i=0;i<numRows;i++)
                    list.Add(new List<int>());
            
                list[0].Add(1);
                for (int i=1;i<numRows;i++)
                {
                    list[i].Add(1);
                    for (int j=1;j<i;j++)
                        list[i].Add(list[i-1][j-1]+list[i-1][j]);
                    list[i].Add(1);
                }
            }
            return list;
        }
    }
    

Log in to reply
 

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