1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-08 18:49:07 +01:00
CodeWars/4kyu/pyramid_slide_down/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

19 lines
453 B
C#

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];
}
}