LeetCode 1344: Angle Between Hands of a Clock Solution

Master LeetCode problem 1344 (Angle Between Hands of a Clock), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

1344. Angle Between Hands of a Clock

Medium

Problem Explanation

Explanation

To solve this problem, we need to calculate the angle between the hour and minute hands of a clock. The hour hand moves 360 degrees in 12 hours, which means it moves 30 degrees per hour or 0.5 degrees per minute. The minute hand moves 360 degrees in 60 minutes, which means it moves 6 degrees per minute. We calculate the angles made by the hour and minute hands from the 12 o'clock position, then find the absolute difference between these angles. The minimum angle between the two hands will be the smaller of the two angles or the absolute difference if they cross over each other.

Solution Code

class Solution {
    public double angleClock(int hour, int minutes) {
        double hourAngle = (hour % 12 + minutes / 60.0) * 30;
        double minuteAngle = minutes * 6;
        
        double angle = Math.abs(hourAngle - minuteAngle);
        return Math.min(angle, 360 - angle);
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 1344 (Angle Between Hands of a Clock)?

This page provides optimized solutions for LeetCode problem 1344 (Angle Between Hands of a Clock) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 1344 (Angle Between Hands of a Clock)?

The time complexity for LeetCode 1344 (Angle Between Hands of a Clock) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 1344 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1344 in Java, C++, or Python.

Back to LeetCode Solutions