Angle Between Hands of a Clock — LeetCode 1344 Python Solution
- Problem
- #1344
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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
- Input
- hour = 12, minutes = 30
- Output
- 165
Python solution
class Solution:
def angleClock(self, hour: int, minutes: int) -> float:
h = 30 * hour + 0.5 * minutes
m = 6 * minutes
diff = abs(h - m)
return min(diff, 360 - diff)Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) or O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 1344. Angle Between Hands of a Clock is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1344. Angle Between Hands of a Clock?
- LeetCode 1344. Angle Between Hands of a Clock is rated Medium on LeetCode.
- What topics does LeetCode 1344. Angle Between Hands of a Clock cover?
- LeetCode 1344. Angle Between Hands of a Clock is tagged Math on LeetCode.