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 e3dddff commit 6c062ffCopy full SHA for 6c062ff
30-days-of-code-july/14.minAngleBetweenHourMinutes.cpp
@@ -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