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

31] Leetcode 1512. Number of Good Pairs

by 깻잎쌈 2020. 7. 12.
반응형

https://leetcode.com/problems/number-of-good-pairs/

 

Number of Good Pairs - 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 numIdenticalPairs(vector<int>& nums) {
        int ans = 0;
        for(int i = 0;i<nums.size();i++)
            for(int j = i+1;j<nums.size();j++)
                if(nums[i] == nums[j])
                    ans++;
        
        return ans;
        
    }
};
반응형

댓글