We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 42344c4 commit 29d8014Copy full SHA for 29d8014
C++/count-pairs-that-form-a-complete-day-i.cpp
@@ -0,0 +1,34 @@
1
+// Time: O(n + 24)
2
+// Space: O(24)
3
+
4
+// freq table
5
+class Solution {
6
+public:
7
+ int countCompleteDayPairs(vector<int>& hours) {
8
+ int result = 0;
9
+ vector<int> cnt(24);
10
+ for (const auto& x : hours) {
11
+ result += cnt[((-x % 24) + 24) % 24];
12
+ ++cnt[x % 24];
13
+ }
14
+ return result;
15
16
+};
17
18
+// Time: O(n^2)
19
+// Space: O(1)
20
+// brute force
21
+class Solution2 {
22
23
24
25
+ for (int i = 0; i + 1 < size(hours); ++i) {
26
+ for (int j = i + 1; j < size(hours); ++j) {
27
+ if ((hours[i] + hours[j]) % 24 == 0) {
28
+ ++result;
29
30
31
32
33
34
0 commit comments