일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- omscs
- 딥러닝
- zeros
- LAA
- 기본
- MATLAB
- 매트랩
- 컴퓨터과학과
- mpnp
- Plotting
- 프로그래머스
- C++
- LV1
- EOI
- 조지아텍
- 방송통신대학교
- 방통대
- 주정부이민
- 머신러닝
- leetcode
- 위니펙
- machine learning
- 코딩테스트
- 개발자
- 온라인석사
- 캐나다 영주권
- 선형대수
- 알고리즘
- Deep learning
- cpp
Archives
- Today
- Total
Byte by Byte
1748. Sum of Unique Elements.cpp 본문

class Solution {
public:
int sumOfUnique(vector<int>& nums) {
set<int>s;
int res=0;
int tmp = nums[0];
int cnt=0;
sort(nums.begin(),nums.end());
for(int i = 0; i< nums.size(); i++){
if(nums[i]==tmp){
cnt++;
}
else{
cnt = 0;
tmp = nums[i];
cnt++;
}
if (cnt>1) s.emplace(nums[i]);
}
for(int i = 0; i< nums.size(); i++){
res+= nums[i];
for(auto it : s){
if(nums[i]==it){
res-= nums[i];
break;
}
}
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1641. Count Sorted Vowel Strings.cpp (0) | 2021.10.08 |
---|---|
1829. Maximum XOR for Each Query.cpp (0) | 2021.10.08 |
961. N-Repeated Element in Size 2N Array.cpp (0) | 2021.10.08 |
589. N-ary Tree Preorder Traversal.cpp (0) | 2021.10.08 |
590. N-ary Tree Postorder Traversal.cpp (0) | 2021.10.08 |