본문 바로가기
IT/알고리즘

38] Leetcode 961. N-Repeated Element in Size 2N Array

by 깻잎쌈 2020. 8. 5.
반응형

 

 

N-Repeated Element in Size 2N Array - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution {
public:
    int repeatedNTimes(vector<int>& A) {
        int array[10001] = {0};
        int ans = 0;
        
        for(int i = 0;i<A.size();i++){
            array[A[i]]++;
            if(array[A[i]] == 2){
                ans = A[i];
                break;
            }
               
        }
            
        return ans;
        
    }
};
반응형

댓글