# 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.

Answers within `10-5` of the actual value will be accepted as correct.

Example 1:

Input: hour = 12, minutes = 30
Output: 165

Example 2:

Input: hour = 3, minutes = 30
Output: 75

Example 3:

Input: hour = 3, minutes = 15
Output: 7.5

Constraints:

• `1 <= hour <= 12`
• `0 <= minutes <= 59`

``````class Solution {
public:
double angleClock(int hour, int minutes) {
double hourDegree = (hour % 12) * 30 + double(minutes) / 60 * 30;
double minDegree = minutes * 6;
double diff = abs(hourDegree - minDegree);
return min(diff, 360 - diff);
}
};
``````

Github 同步地址:

https://github.com/grandyang/leetcode/issues/1344

https://leetcode.com/problems/angle-between-hands-of-a-clock

https://leetcode.com/problems/angle-between-hands-of-a-clock/solutions/735414/c-easy-with-explanation/

https://leetcode.com/problems/angle-between-hands-of-a-clock/solutions/502738/java-python-c-simple-math-on-clock-angles/

LeetCode All in One 题目讲解汇总(持续更新中…)

（欢迎加入博主的知识星球，博主将及时答疑解惑，并分享刷题经验与总结，快快加入吧～）

|

Venmo 打赏

—|—

 微信打赏 Venmo 打赏
（欢迎加入博主的知识星球，博主将及时答疑解惑，并分享刷题经验与总结，试运营期间前五十位可享受半价优惠～）

×

Help us with donation