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

Commit 15ef61d

Browse files
feat: add csharp to lc problem: No.1535 (doocs#1928)
1 parent 40cb6d7 commit 15ef61d

File tree

1 file changed

+17
-0
lines changed
  • solution/1500-1599/1535.Find the Winner of an Array Game

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
public int GetWinner(int[] arr, int k) {
3+
int maxElement = arr[0], count = 0;
4+
for (int i = 1; i < arr.Length; i++) {
5+
if (maxElement < arr[i]) {
6+
maxElement = arr[i];
7+
count = 1;
8+
} else {
9+
count++;
10+
}
11+
if (count == k) {
12+
break;
13+
}
14+
}
15+
return maxElement;
16+
}
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /