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