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