Last active
April 16, 2021 09:39
-
-
Save mesiriak/b13b814ce3997dbc7fbdc8921a0048d0 to your computer and use it in GitHub Desktop.
Codewars. C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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