LeetCode 1344 Angle Between Hands of a Clock (Python)

Posted by 小明MaxMing on July 14, 2020

题目

Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.

解题思路

时针和分针的夹角是5.5 * (hour * 60 + minutes) % 360,然后取小于等于180度的角

代码

class Solution:
    def angleClock(self, hour: int, minutes: int) -> float:
        angle = 5.5 * (hour * 60 + minutes) % 360
        return angle if angle <= 180 else 360 - angle

视频讲解 YouTube<--欢迎点击订阅

视频讲解 bilibili<--欢迎点击订阅