public class Solution {
public int NumIdenticalPairs(int[] nums) {
int goodPairs = 0;
for (var i = 0; i < nums.Length - 1; ++i) {
for (var j = i + 1; j < nums.Length; ++j) {
if (nums[i] == nums[j]) {
++goodPairs;
}
}
}
return goodPairs;
}
}
Source: https://leetcode.com/problems/number-of-good-pairs/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Sunday, February 14, 2021
Leetcode Everyday: 1512. Number of Good Pairs. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment