Number of Good Pairs
Given an integer array nums, return the number of good pairs. A pair (i, j) is good when nums[i] == nums[j] and i < j.
Given an integer array `nums`, return the number of good pairs. A pair `(i, j)` is good when `nums[i] == nums[j]` and `i < j`.
- `1 <= nums.length <= 100` - `-10^9 <= nums[i] <= 10^9` - The interactive visualizer accepts at most 12 values; longer valid arrays are execution-only.
Example 1: input nums = [1,2,3,1,1,3]; output 4. The equal-valued index pairs are (0,3), (0,4), (3,4), and (2,5).
Example 2: input nums = [1,2,3]; output 0. No two positions contain the same value.
Category: Arrays & Hashing. Topic: arrays. Difficulty: Easy. Patterns: hashing.