일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 캐나다 영주권
- omscs
- 딥러닝
- MATLAB
- 개발자
- 머신러닝
- 조지아텍
- 프로그래머스
- 알고리즘
- Plotting
- leetcode
- 방통대
- 위니펙
- machine learning
- cpp
- Deep learning
- mpnp
- 방송통신대학교
- 온라인석사
- EOI
- zeros
- 컴퓨터과학과
- 코딩테스트
- LAA
- 기본
- LV1
- 주정부이민
- C++
- 매트랩
- 선형대수
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 |