759. 时间角度
中文English
计算在时钟中以 h:m 时刻的时针和分针之间的角度。
样例
Example 1:
Input: h = 12, m = 0.
Output: 0
Example 2:
Input: h = 1, m = 0.
Output: 30
注意事项
时针与分针之间的角度小于180度
class Solution: """ @param h: hours @param m: minutes @return: angle between hour hand and minute hand at X:Y in a clock """ ''' 大致思路: 1.一圈12小时,60分钟。那么每小时360//12度每分钟360//60 2.如果大于180度,则360-大于180度即可得到值 ''' def timeAngle(self,h,m): each_h = 360/12 each_m = 360/60 ##不仅是当前多少小时,如果存在多少分钟的话,h也会小小的偏移一点,偏移的角度就是m/60*each_h 在一小时内所占的比例多少*一小时的角度 h = h + m/60 currentAngle = abs(each_m*m - each_h*h) if currentAngle >= 180: return 360 - currentAngle return currentAngle