Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit468013a

Browse files
add 1574
1 parent6f861ca commit468013a

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1574|[Shortest Subarray to be Removed to Make Array Sorted](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1574.java)||Array, Binary Search|Medium|
1112
|1572|[Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1572.java)||Array|Easy|
1213
|1567|[Maximum Length of Subarray With Positive Product](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1567.java)|[:tv:](https://youtu.be/bFer5PdsgpY)|Greedy|Medium|
1314
|1566|[Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1566.java)|[:tv:](https://youtu.be/aJAV_VgmjdE)|Array|Easy|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1574 {
4+
publicstaticclassSolution1 {
5+
publicintfindLengthOfShortestSubarray(int[]arr) {
6+
intleft =0;
7+
while (left <arr.length -1 &&arr[left] <=arr[left +1]) {
8+
left++;
9+
}
10+
if (left ==arr.length -1) {
11+
return0;
12+
}
13+
intright =arr.length -1;
14+
while (right >left &&arr[right] >=arr[right -1]) {
15+
right--;
16+
}
17+
if (right ==0) {
18+
returnarr.length -1;
19+
}
20+
intresult =Math.min(arr.length -left -1,right);
21+
inti =0;
22+
intj =right;
23+
while (i <=left &&j <arr.length) {
24+
if (arr[j] >=arr[i]) {
25+
result =Math.min(result,j -i -1);
26+
i++;
27+
}else {
28+
j++;
29+
}
30+
}
31+
returnresult;
32+
}
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1574;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.TestCase.assertEquals;
8+
9+
publicclass_1574Test {
10+
privatestatic_1574.Solution1solution1;
11+
privatestaticint[]arr;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1574.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
arr =newint[]{1,2,3,10,4,2,3,5};
21+
assertEquals(3,solution1.findLengthOfShortestSubarray(arr));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp