Skip to content

Commit 6c062ff

Browse files
Added day14 solution
1 parent e3dddff commit 6c062ff

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
double angleClock(int hour, int minutes) {
4+
if(hour < 0 or minutes < 0 or hour > 12 or minutes > 60) return 0.0;
5+
6+
if(hour == 12) hour = 0;
7+
if(minutes == 60) {
8+
minutes = 0;
9+
hour += 1;
10+
if(hour > 12) hour -= 12;
11+
}
12+
13+
/*
14+
Minute hand moves => 6 degree per minute
15+
Hour hand moves => 0.5 degree per minute
16+
17+
In h hour and m minutes;
18+
Hour hand moves => (hour * 60 + minutes) * 0.5
19+
Minute hand moves => (hour * 60 + minutes) * 6
20+
*/
21+
auto hour_angle = 0.5 * (hour * 60 + minutes);
22+
auto minute_angle = 6 * minutes;
23+
auto angle = abs(hour_angle - minute_angle);
24+
25+
return min(360 - angle, angle);
26+
}
27+
};

0 commit comments

Comments
 (0)