- 
                            
                            [Algo Rhythm🕺💃] LeetCode - Number of Good PairsAlgo Rhythm🕺💃/LeetCode 2020. 7. 19. 17:01📚 Problem descriptionGiven an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i < j. Return the number of good pairs. Example 1: Input: nums = [1,2,3,1,1,3] 
 Output: 4
 Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.Example 2: Input: nums = [1,1,1,1] 
 Output: 6
 Explanation: Each pair in the array are good.Example 3: Input: nums = [1,2,3] 
 Output: 0Constraints: - 
1 <= nums.length <= 100 
- 
1 <= nums[i] <= 100 
 🎯 My codeclass Solution { public int numIdenticalPairs(int[] nums) { int ans = 0; for(int i = 0;i < nums.length; i++) { for(int j = i + 1; j < nums.length; j++) { if(i == j) continue; if(nums[i] == nums[j]) ans++; } } return ans; } }🧐 Why I wrote that codeTo call a pair (i, j) as 'good', we need to check two conditions. One is whether i is greater than j, and the other is whether nums[i] is equal to nums[j]. Using brute force algorithm, whenever I and j meets two condition, increment number! 📖 What I learnedIt was just simple brute force algorithm. Nothing special😃 'Algo Rhythm🕺💃 > LeetCode' 카테고리의 다른 글[Algo Rhythm🕺💃] LeetCode 90. SubsetsII (0) 2020.08.22 [Algo Rhythm🕺💃] LeetCode 46. Permutations (0) 2020.08.22 [Algo Rhythm🕺💃] LeetCode 1. Two Sum (0) 2020.08.22 [Algo Rhythm🕺💃] LeetCode 784. Letter Case Permutation (0) 2020.07.27 [Algo Rhythm🕺💃] LeetCode - Number of Substrings With Only 1s (0) 2020.07.19 
-