Skip to content

Commit 99abcf8

Browse files
authored
Improved task 3001
1 parent f1387f8 commit 99abcf8

File tree

1 file changed

+6
-8
lines changed
  • src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen

1 file changed

+6
-8
lines changed

src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.kt

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
package g3001_3100.s3001_minimum_moves_to_capture_the_queen
22

3-
// #Medium #Array #Enumeration #2024_02_25_Time_128_ms_(94.59%)_Space_34_MB_(48.65%)
3+
// #Medium #Array #Enumeration #2024_11_09_Time_1_ms_(100.00%)_Space_34.2_MB_(50.00%)
44

55
import kotlin.math.abs
66

77
class Solution {
88
fun minMovesToCaptureTheQueen(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Int {
99
if (a == e || b == f) {
10-
if (a == c && (d > b && d < f || d > f && d < b)) {
10+
if (a == e && a == c && (d - b) * (d - f) < 0) {
1111
return 2
1212
}
13-
if (b == d && (c > a && c < e || c > e && c < a)) {
13+
if (b == f && b == d && (c - a) * (c - e) < 0) {
1414
return 2
1515
}
1616
return 1
17-
} else if (abs(c - e) == abs(d - f)) {
18-
if (abs(a - c) == abs(b - d) &&
19-
abs(e - a) == abs(f - b) &&
20-
(a > e && a < c || a > c && a < e)
21-
) {
17+
}
18+
if (abs(c - e) == abs(d - f)) {
19+
if (abs(c - a) == abs(d - b) && (b - f) * (b - d) < 0) {
2220
return 2
2321
}
2422
return 1

0 commit comments

Comments
 (0)