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

26 lines
627 B
C#

public static class Kata
{
public static int sumTwoSmallestNumbers(int[] numbers)
{
var smallest = new int[] {numbers[0], numbers[1]};
if (smallest[0] > smallest[1]) {
var temp = smallest[0];
smallest[0] = smallest[1];
smallest[1] = temp;
}
for (var i = 2; i < numbers.GetLength(0); i++) {
var number = numbers[i];
if (number < 0) continue;
else if (number < smallest[0]) {
smallest[1] = smallest[0];
smallest[0] = number;
} else if (number < smallest[1]) {
smallest[1] = number;
}
}
return smallest[0] + smallest[1];
}
}