1344. Angle Between Hands of a Clock
1344. Angle Between Hands of a Clock
題目大意:
給你兩個數 hour 和 minutes 。請你返回在時鐘上,由給定時間的時針和分針組成的較小角的角度(60 單位制)。
解題思路:
初始化常數:one_min_angle = 6,one_hour_angle = 30。
分針指標與 0 點垂線的角度為:minutes_angle = one_min_angle * minutes。
時針指標與 0 點垂線的角度為:hour_angle = (hour % 12 + minutes / 60) * one_hour_angle。
得到差:diff = abs(hour_angle - minutes_angle)。
返回最小的角度:min(diff, 360 - diff)。
注意:
None
複雜度:
Time Coplexity: O(1)
Space Complexity: O(1)
Code示例:
class Solution {
public double angleClock(int hour, int minutes) {
int minAngle = 6;
int hourAngle = 30;
double minutesAngle = minAngle * minutes;
double hoursAngle = (hour % 12 + minutes / 60.0) * hourAngle;
double diff = Math.abs(hoursAngle - minutesAngle);
return Math.min(diff, 360-diff);
}
}
相關文章
- Akash Angle:你如何使用 Fedora?
- CLOCK_MONOTONIC 與 CLOCK_REALTIME 區別Mono
- C++(clock())C++
- CSS draws a clockCSS
- Clock——時鐘
- React元件之ClockReact元件
- [Paper Reading] Reconstructing Hands in 3D with TransformersStruct3DORM
- CSS rotate3d(x,y,z,angle)CSS3D
- What is the difference between a Homemaker and a Housewife?
- How to review diffs between commitsViewMIT
- Difference between cursor and a ref cursor
- 藍芽Hands-free和Stereo兩種模式藍芽模式
- 最好用的mac防火牆工具 Hands Off! 4.4.3Mac防火牆
- JavaScript 2/30: JS & CSS ClockJavaScriptJSCSS
- SAP Retail Differences Between Articles and MaterialsAI
- CSS3 rotate3d(x,y,z,angle)CSSS33D
- 世界時鐘:World Clock Deluxe macUXMac
- Between validator常用驗證規則
- In-depth analysis of the comparison between AT and XA of distributed transactions
- MySQL中BETWEEN子句的用法詳解MySql
- [LeetCode] 1385. Find the Distance Value Between Two ArraysLeetCode
- 【Oracle SQL】months_between與trunc函式OracleSQL函式
- [leetcode] 1624. Largest Substring Between Two Equal CharactersLeetCode
- ISO C++ forbids comparison between pointer and integer [-fpermissive]C++ORB
- Difference Between Arraylist And Vector : Core Java Interview Collection QuestionJavaView
- World Clock Deluxe for Mac,世界時鐘豪華版UXMac
- Clock saver for Mac(博朗手錶時鐘屏保)Mac
- Jayson Tatum is a fascinating player who has a sort of in-between kind
- ERROR: failed to establish dependency between database db_name and diskgroupErrorAIDatabase
- Why do STM32 initialization peripherals need to turn on the clock first?
- Google Flutter Clock 大賽優秀專案推薦GoFlutter
- Mac世界時鐘豪華版——World Clock Deluxe for macMacUX
- PostgreSQL DBA(109) - pgAdmin(Don't do this:Don't use BETWEEN)SQL
- Find and Fix the Mismatch Between DBA_SEGMENTS and DBA_EXTENTS ViewsView
- CentOS RHEL 7 Chrony Vs NTP (Differences Between ntpd and chronyd).txtCentOS
- NodeJS中的LRU快取(CLOCK-2-hand)實現NodeJS快取
- Difference between Microsoft Dynamics 365 WEB API, Organization Service and Organization Data ServicROSWebAPI
- 鬧鐘和時間管理工具:Alarm Clock Pro for macMac