1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 11:09:07 +01:00
CodeWars/6kyu/equal_sides_of_an_array/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

23 lines
466 B
C#

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;
}
}