Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@

<!-- 这里可写通用的实现逻辑 -->

时针每小时移动 30 度,每分钟移动 0.5 度。分针每分钟移动 6 度。如果指针之间的夹角大于 180 度,则取其与 360 度的差值,以确保获得最小的夹角。

<!-- tabs:start -->

### **Python3**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

class Solution:
def angleClock(self, hour: int, minutes: int) -> float:
h = 30 * hour + 0.5 * minutes
m = 6 * minutes
diff = abs(h - m)
return min(diff, 360 - diff)
```

### **Java**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@

<!-- tabs:start -->

The hour hand moves 30 degrees every hour and an additional 0.5 degrees for each minute. The minute hand moves 6 degrees every minute. If the angle between the hands is greater than 180 degrees, take its difference from 360 degrees to ensure the smallest angle is obtained.

### **Python3**

```python

class Solution:
def angleClock(self, hour: int, minutes: int) -> float:
h = 30 * hour + 0.5 * minutes
m = 6 * minutes
diff = abs(h - m)
return min(diff, 360 - diff)
```

### **Java**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def angleClock(self, hour: int, minutes: int) -> float:
h = 30 * hour + 0.5 * minutes
m = 6 * minutes
diff = abs(h - m)
return min(diff, 360 - diff)