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