05 August 2008
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);
}
}