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

Commite7014fc

Browse files
add 1535
1 parent7a587ce commite7014fc

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-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+
|1535|[Find the Winner of an Array Game](https://leetcode.com/problems/find-the-winner-of-an-array-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1535.java)||Medium|Array|
1112
|1534|[Count Good Triplets](https://leetcode.com/problems/count-good-triplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1534.java)||Easy|Array|
1213
|1528|[Shuffle String](https://leetcode.com/problems/shuffle-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1528.java)||Easy|Sort|
1314
|1526|[Minimum Number of Increments on Subarrays to Form a Target Array](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1526.java)||Hard|Segment Tree|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1535 {
4+
publicstaticclassSolution1 {
5+
publicintgetWinner(int[]arr,intk) {
6+
intwinner =arr[0];
7+
intwinTimes =0;
8+
for (inti =1;i <arr.length;i++) {
9+
if (arr[i] >winner) {
10+
winner =arr[i];
11+
winTimes =1;
12+
}else {
13+
winTimes++;
14+
}
15+
16+
if (winTimes >=k) {
17+
returnwinner;
18+
}
19+
}
20+
returnwinner;
21+
}
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1535;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.TestCase.assertEquals;
8+
9+
publicclass_1535Test {
10+
privatestatic_1535.Solution1solution1;
11+
privatestaticint[]arr;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1535.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
arr =newint[]{2,1,3,5,4,6,7};
21+
assertEquals(5,solution1.getWinner(arr,2));
22+
}
23+
24+
@Test
25+
publicvoidtest2() {
26+
arr =newint[]{1,11,22,33,44,55,66,77,88,99};
27+
assertEquals(99,solution1.getWinner(arr,100));
28+
}
29+
30+
@Test
31+
publicvoidtest3() {
32+
arr =newint[]{1,9,8,2,3,7,6,4,5};
33+
assertEquals(9,solution1.getWinner(arr,7));
34+
}
35+
36+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp