diff --git a/src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.kt b/src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.kt index a496ed782..fde139a1e 100644 --- a/src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.kt @@ -1,24 +1,22 @@ package g3001_3100.s3001_minimum_moves_to_capture_the_queen -// #Medium #Array #Enumeration #2024_02_25_Time_128_ms_(94.59%)_Space_34_MB_(48.65%) +// #Medium #Array #Enumeration #2024_11_09_Time_1_ms_(100.00%)_Space_34.2_MB_(50.00%) import kotlin.math.abs class Solution { fun minMovesToCaptureTheQueen(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Int { if (a == e || b == f) { - if (a == c && (d > b && d < f || d > f && d < b)) { + if (a == e && a == c && (d - b) * (d - f) < 0) { return 2 } - if (b == d && (c > a && c < e || c > e && c < a)) { + if (b == f && b == d && (c - a) * (c - e) < 0) { return 2 } return 1 - } else if (abs(c - e) == abs(d - f)) { - if (abs(a - c) == abs(b - d) && - abs(e - a) == abs(f - b) && - (a > e && a < c || a > c && a < e) - ) { + } + if (abs(c - e) == abs(d - f)) { + if (abs(c - a) == abs(d - b) && (b - f) * (b - d) < 0) { return 2 } return 1