Skip to content

Commit e718e71

Browse files
solves #3184: Count Pairs That Form a Complete Day I in java
1 parent 8f2fb41 commit e718e71

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@
918918
| 3173 | 🔒 [Bitwise OR of Adjacent Elements](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | | |
919919
| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits) | [![Java](assets/java.png)](src/ClearDigits.java) | |
920920
| 3178 | [Find the Child Who Has the Ball After K Seconds](https://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds) | [![Java](assets/java.png)](src/FindTheChildWhoHasTheBallAfterKSeconds.java) | |
921-
| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | | |
921+
| 3184 | [Count Pairs That Form a Complete Day I](https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i) | [![Java](assets/java.png)](src/CountPairsThatFormACompleteDayI.java) | |
922922
| 3190 | [Find Minimum Operations to Make All Elements Divisible by Three](https://leetcode.com/problems/find-minimum-operations-to-make-all-elements-divisible-by-three) | | |
923923
| 3194 | [Minimum Average of Smallest and Largest Elements](https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements) | | |
924924
| 3199 | [Count Triplets With Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i) | | |

Diff for: src/CountPairsThatFormACompleteDayI.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// https://leetcode.com/problems/count-pairs-that-form-a-complete-day-i
2+
// T: O(N)
3+
// S: O(N)
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
public class CountPairsThatFormACompleteDayI {
9+
public int countCompleteDayPairs(int[] hours) {
10+
final Map<Integer, Integer> frequencies = new HashMap<>();
11+
int pairs = 0;
12+
13+
for (int element : hours) {
14+
int required = (24 - (element % 24)) % 24;
15+
int current = element % 24;
16+
pairs += frequencies.getOrDefault(required, 0);
17+
frequencies.put(current, frequencies.getOrDefault(current, 0) + 1);
18+
}
19+
20+
return pairs;
21+
}
22+
}

0 commit comments

Comments
 (0)