1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-18 21:56:57 +02:00
CodeWars/8kyu/sum_without_highest_and_lowest/solution.cpp

25 lines
386 B
C++
Raw Normal View History

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