题目
Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
题解
这题 N^2 也能过
1 | class Solution: |
然后优化一下的话,就是用 hash 表记录一下之前出现的频率就行
1 | from collections import defaultdict |
Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
这题 N^2 也能过
1 | class Solution: |
然后优化一下的话,就是用 hash 表记录一下之前出现的频率就行
1 | from collections import defaultdict |