mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-22 08:33:48 +01:00
19 lines
453 B
C#
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];
|
|
}
|
|
}
|