Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update 1512. good pairs.cpp
  • Loading branch information
Sidd7000 authored Oct 17, 2023
commit ddbfc3d4a84b5a5dd3d68dfc9996b478abdc9d95
4 changes: 4 additions & 0 deletions C++/1512. good pairs.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include <bits/stdc++.h>

using namespace std;

int numIdenticalPairs(vector<int>& nums) {
unordered_map<int, int> count;

// Count the occurrences of each number
for (int num : nums) {
count[num]++;
}

int goodPairs = 0;

// Calculate the number of good pairs for each number
for (const auto& pair : count) {
int occurrences = pair.second;
if (occurrences >= 2) {
Expand Down