首页 > 代码库 > leetcode119

leetcode119

public class Solution {
    public IList<int> GetRow(int rowIndex) {
        List<List<int>> list = new List<List<int>>();
            for (int i = 0; i <= rowIndex; i++)
            {
                var row = new List<int>();
                if (i == 0)
                {
                    row.Add(1);
                }
                else if (i == 1)
                {
                    row.Add(1);
                    row.Add(1);
                }
                else//i>=3
                {
                    for (int j = 0; j <= i; j++)
                    {
                        if (j == 0)
                        {
                            row.Add(1);
                        }
                        else if (j == i)
                        {
                            row.Add(1);
                        }
                        else
                        {
                            var pre = list[i - 1];
                            row.Add(pre[j - 1] + pre[j]);
                        }
                    }
                }
                list.Add(row);
            }
            var result = list.LastOrDefault();
            return result;
    }
}

https://leetcode.com/problems/pascals-triangle-ii/#/description

leetcode119