sum of unique elements in array
Anonymous User
132
Jan 29, 2022
Jan 29, 2022

class Solution {
public :
int sumOfUnique(vector& nums) {
vector v;
for(auto x:nums)
if(count(nums.begin(), nums.end(), x) == 1) // taking values whose count is 1
// are whose values is repaeted once //
v.push_back(x); // values which are repaeted once are s
// simply pushed into vetcor v//
int x=accumulate(v.begin(), v.end(), 0);
// syntax accumulate = (first ,last, 0)
// where fist and last gives us the range and 0 is the value of initial sum
// that is initialized to 0//
// accumulate func gives sum of values presnet in vector v

      return x;
}  

};

Comments (0)