Skip to content

Commit 11fa31b

Browse files
add 2717
1 parent 77f2253 commit 11fa31b

File tree

3 files changed

+47
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+47
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2733.java) | | Easy |
2121
| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2729.java) | | Easy |
2222
| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2728.java) | | Easy |
23+
| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2717.java) | | Easy |
2324
| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2716.java) | [:tv:](https://youtu.be/aMJ3T0K8LjI) | Easy |
2425
| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2710.java) | | Easy |
2526
| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2706.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2717 {
4+
public static class Solution1 {
5+
public int semiOrderedPermutation(int[] nums) {
6+
int[] max = new int[]{nums[0], 0};
7+
int[] min = new int[]{nums[0], 0};
8+
for (int i = 1; i < nums.length; i++) {
9+
if (nums[i] > max[0]) {
10+
max[0] = nums[i];
11+
max[1] = i;
12+
}
13+
if (nums[i] < min[0]) {
14+
min[0] = nums[i];
15+
min[1] = i;
16+
}
17+
}
18+
if (max[1] > min[1]) {
19+
return nums.length - max[1] - 1 + min[1];
20+
}
21+
return nums.length - max[1] - 1 + min[1] - 1;
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2717;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2717Test {
10+
private static _2717.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2717.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.semiOrderedPermutation(new int[]{2, 1, 4, 3}));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)