2
2
id : find-the-winner-of-the-circular-game
3
3
title : Find the Winner of the Circular Game
4
4
sidebar_label : 1823 - Find the Winner of the Circular Game
5
- tags : [Array]
5
+ tags :
6
+ - Array
7
+
6
8
description : " This is a solution to the Find the Winner of the Circular Game problem on LeetCode."
7
9
---
8
10
@@ -11,7 +13,7 @@ There are n friends that are playing a game. The friends are sitting in a circle
11
13
12
14
### Examples
13
15
14
- * Example 1:*
16
+ ** Example 1:* *
15
17
16
18
```
17
19
Input: n = 5, k = 2
@@ -28,7 +30,7 @@ Explanation: Here are the steps of the game:
28
30
9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
29
31
```
30
32
31
- * Example 2:*
33
+ ** Example 2:* *
32
34
```
33
35
Input: n = 6, k = 5
34
36
Output: 1
@@ -45,11 +47,11 @@ Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is frien
45
47
1 . ** Initialization** :
46
48
- Initialize a variable ` winner ` to keep track of the winner found.
47
49
48
- 2 . * Iterate Through the Numbers* :
50
+ 2 . ** Iterate Through the Numbers* * :
49
51
- Use a loop to iterate through each element.
50
52
- Apply the formula ` (winner + k - 1) % (i + 1) + 1 ` to find the new winner.
51
53
52
- 3 . * Return the Result* :
54
+ 3 . ** Return the Result* * :
53
55
- After iterating through all elements, return the value of ` winner ` as the result.
54
56
55
57
<Tabs >
@@ -83,13 +85,12 @@ function Solution() {
83
85
</div >
84
86
);
85
87
}
86
-
87
- ```
88
+ ```
88
89
89
90
#### Complexity Analysis
90
91
91
- - ** Time Complexity:** $ O(n) $ because of iterating through the elements
92
- - ** Space Complexity:** $ O(1) $
92
+ - Time Complexity: $ O(n) $ because of iterating through the elements
93
+ - Space Complexity: $ O(1) $
93
94
94
95
## Code in Different Languages
95
96
<Tabs>
@@ -147,7 +148,6 @@ public class Solution {
147
148
}
148
149
```
149
150
</TabItem >
150
-
151
151
<TabItem value =" C++ " label =" C++ " >
152
152
<SolutionAuthor name =" @Ishitamukherjee2004 " />
153
153
``` cpp
@@ -165,10 +165,13 @@ public:
165
165
</TabItem>
166
166
</Tabs>
167
167
168
+ </TabItem>
169
+ </Tabs>
168
170
169
171
170
172
171
173
## References
172
174
173
- - *LeetCode Problem*: [Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
174
- - *Solution Link*: [LeetCode Solution](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
175
+ - **LeetCode Problem**: [Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
176
+
177
+ - **Solution Link**: [LeetCode Solution](https://leetcode.com/problems/find-the-winner-of-the-circular-game)
0 commit comments