LeetCode Entry
1344. Angle Between Hands of a Clock
Angle between clock arrows
1344. Angle Between Hands of a Clock medium substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1394
Problem TLDR
Angle between clock arrows
Intuition
- 360 degrees full circle
- 360/60=6 degrees one hour
- h*60+m total minutes M
- 5.5*M%360 periodic angle between hands of a clock
Approach
- Rust: successors
Complexity
-
Time complexity: \(O(1)\)
-
Space complexity: \(O(1)\)
Code
fun angleClock(h: Int, m: Int) =
180-abs(abs(h*30-5.5*m)-180)
pub fn angle_clock(h: i32, m: i32) -> f64 {
successors(Some(0.0f64),|a|Some((a+5.5)%360.))
.nth((h*60+m)as usize %720).map(|a|a.min(360.-a)).unwrap()
}
Comments