Skip to content

Commit e7f494c

Browse files
authored
[20251202] PGM / LV2 / 아날로그 시계 / 한종욱
1 parent ea453b2 commit e7f494c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```
2+
class Solution {
3+
static final int FULL_CIRCLE = 43200;
4+
5+
public int solution(int h1, int m1, int s1, int h2, int m2, int s2) {
6+
int start = h1 * 3600 + m1 * 60 + s1;
7+
int end = h2 * 3600 + m2 * 60 + s2;
8+
9+
int answer = countAlarms(end) - countAlarms(start);
10+
11+
if (isExactOverlap(start)) {
12+
answer++;
13+
}
14+
15+
return answer;
16+
}
17+
18+
private int countAlarms(int time) {
19+
int mCount = time * 59 / 3600;
20+
int hCount = time * 719 / 43200;
21+
22+
int overlap = time / 43200;
23+
24+
return mCount + hCount - overlap;
25+
}
26+
27+
private boolean isExactOverlap(int time) {
28+
if (time % 43200 == 0) {
29+
return true;
30+
}
31+
32+
double secondAngle = (time % 60) * 6.0;
33+
double minuteAngle = (time % 3600) * 0.1;
34+
double hourAngle = (time % 43200) * (1.0 / 120.0);
35+
36+
return Math.abs(secondAngle - minuteAngle) < 0.01 ||
37+
Math.abs(secondAngle - hourAngle) < 0.01;
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)