Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 352 Bytes

1535. Find the Winner of an Array Game.md

File metadata and controls

21 lines (17 loc) · 352 Bytes

Code for ' 1535. Find the Winner of an Array Game ' (C++)

class Solution {
  public int getWinner(int[] arr, int k) {
    int ans = arr[0];
    int wins = 0;

    for (int i = 1; i < arr.length && wins < k; ++i)
      if (arr[i] > ans) {
        ans = arr[i];
        wins = 1;
      } else {
        ++wins;
      }

    return ans;
  }
}