Arrays
#include <bits/stdc++.h> using namespace std; int unique_sum(const vector<int>& n) { auto nums = n; sort(nums.begin(), nums.end(), [](int a, int b) { return a < b; }); int sum = 0; for(size_t i = 0; i < nums.size(); i++) { if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) { continue; } else { sum += nums[i]; } } return sum; }
#include <iostream>#include <vector>#include <algorithm>#include <cassert>- #include <bits/stdc++.h>
- using namespace std;
- int unique_sum(const vector<int>& n) {
- auto nums = n;
- sort(nums.begin(), nums.end(), [](int a, int b) {
- return a < b;
- });
- int sum = 0;
- for(size_t i = 0; i < nums.size(); i++) {
- if(nums[i] == nums[i+1] || nums[i] == nums[i-1]) {
- continue;
- } else {
- sum += nums[i];
- }
- }
- return sum;
- }