1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-22 16:43:46 +01:00
CodeWars/4kyu/pyramid_slide_down/solution.cs

20 lines
453 B
C#
Raw Normal View History

using System;
public class PyramidSlideDown
{
public static int LongestSlideDown(int[][] pyramid)
{
for (var i = pyramid.GetLength(0) - 2; i >= 0; i--) {
for (var j = 0; j <= i; j++) {
if (pyramid[i + 1][j] > pyramid[i + 1][j + 1]) {
pyramid[i][j] += pyramid[i + 1][j];
} else {
pyramid[i][j] += pyramid[i + 1][j + 1];
}
}
}
return pyramid[0][0];
}
}