This commit is contained in:
Electrominch
2022-10-07 00:48:48 +03:00
parent 0b88604037
commit e711e64e07
18 changed files with 45 additions and 45 deletions

View File

@@ -5,19 +5,19 @@ public class Solution
public IList<IList<int>> Generate(int numRows)
{
List<IList<int>> triangle = new List<IList<int>>() { new List<int> { 1 } };
if(numRows > 1)
triangle.Add(new List<int>() { 1,1 });
if (numRows > 1)
triangle.Add(new List<int>() { 1, 1 });
numRows -= 2;
while (numRows-- > 0)
{
IList<int> prev = triangle[^1];
int nextCount = prev.Count;
List<int> row = new List<int>() { 1 };
for(int i = 1; i < nextCount; i++)
for (int i = 1; i < nextCount; i++)
{
row.Add(prev[i-1] + prev[i]);
row.Add(prev[i - 1] + prev[i]);
}
row.Add(1);
row.Add(1);
triangle.Add(row);
}