Skip to content

Commit fe35e6b

Browse files
add 4061
1 parent f92331b commit fe35e6b

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

  • paginated_contents/algorithms/5th_thousand
  • src

‎paginated_contents/algorithms/5th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|------------|----------------------------------------------------------------------
33
| 4065 | [Rearrange Array by Removing Distinct Values](https://leetcode.com/problems/rearrange-array-by-removing-distinct-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4065.java) | | Easy |
4+
| 4061 | [Minimum Queen Moves to Reach Target](https://leetcode.com/problems/minimum-queen-moves-to-reach-target/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4061.java) | | Easy |
45
| 4056 | [Number of Intersecting Interval Pairs I](https://leetcode.com/problems/number-of-intersecting-interval-pairs-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4056.java) | | Easy |
56
| 4052 | [Cyclically Shift Rows and Columns](https://leetcode.com/problems/cyclically-shift-rows-and-columns/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4052.java) | | Easy |
67
| 4048 | [Count Values With Equally Spaced Occurrences I](https://leetcode.com/problems/count-values-with-equally-spaced-occurrences-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fifththousand/_4048.java) | | Easy |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions.fifththousand;
2+
3+
public class _4061 {
4+
public static class Solution1 {
5+
/**
6+
* Only three possible answers: 0, 1, 2:
7+
*
8+
* 1. If they are at the same position, then zero;
9+
* 2. If they share the same row, or column, or diagonal, one only move is needed;
10+
* 3. In all other cases, they can make two moves to reach
11+
*/
12+
public int minQueenMoves(int[] source, int[] target) {
13+
if (source[0] == target[0] && source[1] == target[1]) {
14+
return 0;
15+
} else if (Math.abs(source[0] - target[0]) == Math.abs(source[1] - target[1]) //this means they are on the same diagonal
16+
|| source[0] == target[0] // this means they are on the same row
17+
|| source[1] == target[1] // this means they are on the same column
18+
) {
19+
return 1;
20+
} else {
21+
return 2;
22+
}
23+
}
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.fifththousand;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.fishercoder.solutions.fifththousand._4061;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class _4061Test {
10+
private _4061.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _4061.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.minQueenMoves(new int[] {1, 8}, new int[] {3, 1}));
20+
}
21+
}

0 commit comments

Comments
 (0)