1344. Angle Between Hands of a Clock
Problem description:
Given two numbers, hour
and minutes
. Return the smaller angle (in degrees) formed between the hour
and the minute
hand.
Example 1:
1 | Input: hour = 12, minutes = 30 |
Example 2:
1 | Input: hour = 3, minutes = 30 |
Example 3:
1 | Input: hour = 3, minutes = 15 |
Example 4:
1 | Input: hour = 4, minutes = 50 |
Example 5:
1 | Input: hour = 12, minutes = 0 |
Constraints:
1 <= hour <= 12
0 <= minutes <= 59
- Answers within
10^-5
of the actual value will be accepted as correct.
Solution:
Hour HandIn 12 hours Hour hand complete whole circle and cover 360°So, 1 hour = 360° / 12 = 30°
Since 1 hours = 30°In 1 minute, hours hand rotate -> 30° / 60 = 0.5°So total angle because of minutes by hour hand is minutes/60 * 30
or minutes * 0.5
Minute HandIn 60 minutes Minute Hand completes whole circle and cover 360°.So, 1 minute -> 360° / 60 = 6°
1 | class Solution: |
time complexity: $O(1)$
space complexity: $O(1)$
reference:
related problem: