1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 19:19:07 +01:00
CodeWars/6kyu/equal_sides_of_an_array/solution.cs

24 lines
466 B
C#
Raw Normal View History

public class Kata
{
public static int SumOfTheArray(int[] arr)
{
int sum = 0;
for (int i = 0, max = arr.Length; i < max; sum += arr[i++]);
return sum;
}
public static int FindEvenIndex(int[] arr)
{
int left, right;
left = 0;
right = SumOfTheArray(arr) - arr[0];
for (int i = 1, max = arr.Length; i < max; i++)
{
left += arr[i - 1];
right -= arr[i];
if (left == right) return i;
}
return -1;
}
}