GuilinDev

Lc1344

05 August 2008

1344. Angle Between Hands of a Clock

给时针和分针求60单位制的角度 - Math

O(1)

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
  public double angleClock(int hour, int minutes) {
    int oneMinAngle = 6;
    int oneHourAngle = 30;

    double minutesAngle = oneMinAngle * minutes;
    double hourAngle = (hour % 12 + minutes / 60.0) * oneHourAngle;

    double diff = Math.abs(hourAngle - minutesAngle);
    return Math.min(diff, 360 - diff);
  }
}