Skip to content

Instantly share code, notes, and snippets.

@mesiriak
Last active April 16, 2021 09:39
Show Gist options
  • Save mesiriak/b13b814ce3997dbc7fbdc8921a0048d0 to your computer and use it in GitHub Desktop.
Save mesiriak/b13b814ce3997dbc7fbdc8921a0048d0 to your computer and use it in GitHub Desktop.
Codewars. C#
using System;
using System.Linq;
public class PyramidSlideDown
{
public static int LongestSlideDown(int[][] pyramid)
{
for (int i = 1; i < pyramid.Length; i++)
for (int j = 0; j < pyramid[i].Length; j++)
if (j == 0) { pyramid[i][j] += pyramid[i - 1][j]; }
else if (j == pyramid[i].Length -1) { pyramid[i][j] += pyramid[i - 1][j - 1]; }
else {pyramid[i][j] += Math.Max(pyramid[i - 1][j], pyramid[i - 1][j - 1]);}
return pyramid[pyramid.Length - 1].Max();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment