其他分享
首页 > 其他分享> > 1344. Angle Between Hands of a Clock

1344. Angle Between Hands of a Clock

作者:互联网

This is an absolutely math problem:

1. calculate minute angle: 360/60*minutes

2. calculate hour angle: 360/12*hour%12

3. calculate hour angle's plus, because the hour hand cannot jump from one hour to another, it should be somewhere between two hours according to minutes: (360/12)*(munutes/(360/60))

4. The angle either be smaller than 180 or larger than 180, if it's larger than 180, we need (360-angle).

    public double angleClock(int hour, int minutes) {
        double minAngle = minutes * 6;
        double hourAngle = hour%12 * 30;
        double hourAnglePlus = 30*minutes/60.0;
        hourAngle += hourAnglePlus;
        double res = Math.abs(hourAngle-minAngle);
        if(res>180)             //or res = Math.min(res, 360-res);
            return 360-res;
        else
            return res;       
    }

 

标签:Angle,hour,Clock,res,double,Hands,angle,minutes,360
来源: https://www.cnblogs.com/feiflytech/p/15861138.html