Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c3b894

Browse files
committedMay 14, 2023
solves #2176: Count Equal and Divisible Pairs in an Array in java
1 parent 66cfb13 commit 0c3b894

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@
713713
| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | |
714714
| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | |
715715
| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | |
716-
| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | |
716+
| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | [![Java](assets/java.png)](src/CountEqualAndDivisiblePairsInAnArray.java) | |
717717
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
718718
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | |
719719
| 2190 | [Most Frequent Number Following Key In an Array](https://leetcode.com/problems/most-frequent-number-following-key-in-an-array) | | |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array
2+
// T: O(n^2)
3+
// S: O(1)
4+
5+
public class CountEqualAndDivisiblePairsInAnArray {
6+
public int countPairs(int[] nums, int k) {
7+
int pairs = 0;
8+
for (int i = 0 ; i < nums.length ; i ++) {
9+
for (int j = i + 1 ; j < nums.length ; j++) {
10+
if (nums[i] == nums[j] && (i * j) % k == 0) pairs++;
11+
}
12+
}
13+
return pairs;
14+
}
15+
}

0 commit comments

Comments
 (0)
Please sign in to comment.