We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 40cb6d7 commit 15ef61dCopy full SHA for 15ef61d
solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs
@@ -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