File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Time: O(1)
2
+ // Space: O(1)
3
+
4
+ class Solution {
5
+ public:
6
+ int numberOfRounds (string startTime, string finishTime) {
7
+ int start = stoi (startTime.substr (0 , 2 )) * 60 + stoi (startTime.substr (3 ));
8
+ int finish = stoi (finishTime.substr (0 , 2 )) * 60 + stoi (finishTime.substr (3 ));
9
+ if (start > finish) {
10
+ finish += 1440 ;
11
+ }
12
+ return max (finish / 15 - (start + 15 - 1 ) / 15 , 0 );
13
+ }
14
+ };
15
+
16
+
17
+ // Time: O(1)
18
+ // Space: O(1)
19
+ class Solution2 {
20
+ public:
21
+ int numberOfRounds (string startTime, string finishTime) {
22
+ int h1 = stoi (startTime.substr (0 , 2 ));
23
+ int m1 = stoi (startTime.substr (3 ));
24
+ int h2 = stoi (finishTime.substr (0 , 2 ));
25
+ int m2 = stoi (finishTime.substr (3 ));
26
+ if (m1 > m2) {
27
+ --h2;
28
+ m2 += 60 ;
29
+ }
30
+ return max ((h2 - h1 + 24 ) % 24 * 4 + m2 / 15 - (m1 + 15 - 1 ) / 15 , 0 );
31
+ }
32
+ };
You can’t perform that action at this time.
0 commit comments