Posted on

Description

Submission

class Solution {
public:
    double angleClock(int hour, int minutes) {
        hour = hour % 12;
        double minuteAngle = minutes * 360 / 60;
        double hourAngle = double(hour * 60 + minutes) / (12 * 60) * 360;
        double angle = minuteAngle > hourAngle ? minuteAngle - hourAngle : hourAngle - minuteAngle;
        if(angle > 180) angle = 360 - angle;
        return angle;
    }
};

Submission 210322

class Solution {
public:
    double angleClock(int hour, int minutes) {
        if(hour == 12) hour = 0;
        double hAngle = (hour + (double)minutes / 60) * 30;
        double mAngle = minutes * 6;

        double ret = abs(hAngle - mAngle);
        
        return ret > 180 ? 360 - ret : ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *