728x90
문제
Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.
Example 1:
Input: hour = 12, minutes = 30 Output: 165
Example 2:
Input: hour = 3, minutes = 30 Output: 75
Example 3:
Input: hour = 3, minutes = 15 Output: 7.5
Example 4:
Input: hour = 4, minutes = 50 Output: 155
Example 5:
Input: hour = 12, minutes = 0 Output: 0
Constraints:
- 1 <= hour <= 12
- 0 <= minutes <= 59
- Answers within 10^-5 of the actual value will be accepted as correct.
분침에 따라 시침도 바뀐다는 것과 360도는 0도로 바꿔주는 것, 두 침의 작은 각을 반환해야 하는것만 생각해주면 된다.
class Solution {
func angleClock(_ hour: Int, _ minutes: Int) -> Double {
var mAngle : Double = 6*Double(minutes)
var hAngle : Double = ( (30*Double(hour)) + (30*Double(minutes)/60) )
if hAngle >= 360 { hAngle -= 360 }
var minAngle = min(abs(hAngle-mAngle),abs(mAngle-hAngle))
return min(abs(360-minAngle),minAngle)
}
}
728x90
'Algorithm > LeetCode' 카테고리의 다른 글
💯 Daily LeetCode Challenge Day_16 - Pow(x, n) (0) | 2020.07.18 |
---|---|
💯 Daily LeetCode Challenge Day_15 - Reverse Words in a String (0) | 2020.07.16 |
LeetCode - Container With Most Water (0) | 2020.07.14 |
💯 Daily LeetCode Challenge Day_13 - Same Tree (0) | 2020.07.13 |
💯 Daily LeetCode Challenge Day_12 - Reverse Bits (0) | 2020.07.12 |
댓글