1512. Number of Good Pairs ¶ Time: $O(n)$ Space: $O(101) = O(1)$ C++ 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int numIdenticalPairs(vector<int>& nums) { int ans = 0; vector<int> count(101); for (const int num : nums) ans += count[num]++; return ans; } };