일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- 마니토바
- 선형대수
- zeros
- 방송통신대학교
- machine learning
- 컴퓨터과학과
- 코딩테스트
- MATLAB
- 딥러닝
- LAA
- Deep learning
- 방통대
- 기본
- mpnp
- 머신러닝
- omscs
- 주정부이민
- 매트랩
- EOI
- cpp
- Plotting
- 조지아텍
- 온라인석사
- leetcode
- 알고리즘
- LV1
- 개발자
- 캐나다 영주권
- C++
Archives
- Today
- Total
Krononberg
961. N-Repeated Element in Size 2N Array.cpp 본문
class Solution {
public:
int repeatedNTimes(vector<int>& nums) {
int n = nums.size()/2;
sort(nums.begin(),nums.end());
int tmp = nums[0];
int cnt = 0;
for(int i=0; i<nums.size(); i++){
if(nums[i]==tmp){
cnt++;
}
else{
tmp = nums[i];
cnt = 0;
cnt++;
}
if(cnt==n) return nums[i];
}
return -1;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1829. Maximum XOR for Each Query.cpp (0) | 2021.10.08 |
---|---|
1748. Sum of Unique Elements.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 |
1261. Find Elements in a Contaminated Binary Tree.cpp (0) | 2021.10.08 |