Sunday, February 14, 2021

Leetcode Everyday: 1512. Number of Good Pairs. Easy

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/

No comments:

Post a Comment