码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode119

时间:2017-04-22 09:21:52      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:problem   win   solution   problems   var   title   leetcode   triangle   etc   

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

标签:problem   win   solution   problems   var   title   leetcode   triangle   etc   

原文地址:http://www.cnblogs.com/asenyang/p/6746832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!