From ce626165ca6f163bd0082d354ecc888f783d49a5 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Sun, 5 Nov 2023 12:36:38 +0530 Subject: [PATCH 1/2] feat: add solutions to lc problem: No.1535 Added solution.cs for problem no 1535 --- .../solution.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs diff --git a/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs b/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs new file mode 100644 index 0000000000000..2f9a67383aec6 --- /dev/null +++ b/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs @@ -0,0 +1,18 @@ +public class Solution { + public int GetWinner(int[] arr, int k) { + int maxElement = arr[0], count = 0; + for (int i = 1; i < arr.Length; i++) { + if (maxElement < arr[i]){ + maxElement = arr[i]; + count = 1; + } + else { + count++; + } + if (count == k) { + break; + } + } + return maxElement; + } +} From da31297286d8c667c96ca7f94c9b30a6c6689f22 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Sun, 5 Nov 2023 22:39:29 +0800 Subject: [PATCH 2/2] Update solution.cs --- .../1535.Find the Winner of an Array Game/solution.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs b/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs index 2f9a67383aec6..8f495550493d3 100644 --- a/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs +++ b/solution/1500-1599/1535.Find the Winner of an Array Game/solution.cs @@ -2,11 +2,10 @@ public class Solution { public int GetWinner(int[] arr, int k) { int maxElement = arr[0], count = 0; for (int i = 1; i < arr.Length; i++) { - if (maxElement < arr[i]){ + if (maxElement < arr[i]) { maxElement = arr[i]; count = 1; - } - else { + } else { count++; } if (count == k) {