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

24 lines
386 B
C++

#include<vector>
using namespace std;
int sum(vector<int> numbers)
{
if (numbers.size() < 3) return 0;
int min = numbers[0];
int max = numbers[0];
int result = 0;
for (const int num : numbers)
{
if (num < min)
min = num;
else if (num > max)
max = num;
result += num;
}
return result - (min + max);
}