主题:面经
题目:
In a clock, calculate the angle between hour and minute handle
Code:
class Test{
public static void main(String[] args){
Solution sol = new Solution();
int h = 6, min = 45;
System.out.println(sol.timeAngle(h, min));
}
}
class Solution{
public double timeAngle(int h, int min){
double rev = (double)min/2;
double h_d = (double)h*30 + rev;
double min_d = (double)min*6;
return Math.abs(h_d-min_d);
// return Math.min(Math.abs(h_d-min_d), 180-Math.abs(h_d-min_d));
}
}
CC150原题。