From 79fa6b9ea1d3f1da4f029a23f93c3353da85fbf7 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 8 Nov 2024 06:41:58 +0200 Subject: [PATCH 1/2] Improved task 3001 --- .../Solution.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java index 892388c5a..787269644 100644 --- a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java +++ b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java @@ -1,21 +1,20 @@ package g3001_3100.s3001_minimum_moves_to_capture_the_queen; -// #Medium #Array #Enumeration #2024_02_25_Time_0_ms_(100.00%)_Space_40.7_MB_(78.00%) +// #Medium #Array #Enumeration #2024_11_08_Time_0_ms_(100.00%)_Space_41_MB_(27.27%) public class Solution { public int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) { 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 (Math.abs(c - e) == Math.abs(d - f)) { - if (Math.abs(a - c) == Math.abs(b - d) - && Math.abs(e - a) == Math.abs(f - b) - && (a > e && a < c || a > c && a < e)) { + } + if (Math.abs(c - e) == Math.abs(d - f)) { + if (Math.abs(c - a) == Math.abs(d - b) && ((b - f) * (b - d) < 0)) { return 2; } return 1; From b855aff4d7a8c169110bff997574d86dd8c04ca0 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Fri, 8 Nov 2024 06:44:47 +0200 Subject: [PATCH 2/2] Fixed style --- .../s3001_minimum_moves_to_capture_the_queen/Solution.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java index 787269644..95e2ae26b 100644 --- a/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java +++ b/src/main/java/g3001_3100/s3001_minimum_moves_to_capture_the_queen/Solution.java @@ -5,16 +5,16 @@ public class Solution { public int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) { if (a == e || b == f) { - if (a == e && a == c && ((d - b) * (d - f) < 0)) { + if (a == e && a == c && (d - b) * (d - f) < 0) { return 2; } - if (b == f && b == d && ((c - a) * (c - e) < 0)) { + if (b == f && b == d && (c - a) * (c - e) < 0) { return 2; } return 1; } if (Math.abs(c - e) == Math.abs(d - f)) { - if (Math.abs(c - a) == Math.abs(d - b) && ((b - f) * (b - d) < 0)) { + if (Math.abs(c - a) == Math.abs(d - b) && (b - f) * (b - d) < 0) { return 2; } return 1;