Skip to content

Commit b8bb8ef

Browse files
authored
Create count-pairs-that-form-a-complete-day-ii.cpp
1 parent 29d8014 commit b8bb8ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n + 24)
2+
// Space: O(24)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
long long countCompleteDayPairs(vector<int>& hours) {
8+
int64_t 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+
};

0 commit comments

Comments
 (0)