[LeetCode] Angle Between Hands of a Clock

1344. Angle Between Hands of a Clock

Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.

1
2
3
4
5
6
7
8
class Solution {
public:
double angleClock(int hour, int minutes) {
double h(hour == 12 ? 0 + 1 / minutes : 30 * hour + 1 / minutes), m(6 * minutes);

return min(max(h,m) - min(h,m), 360 - (max(h,m) - min(h,m)));
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2021/06/20/PS/LeetCode/angle-between-hands-of-a-clock/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.