Skip to content

Commit cbe316b

Browse files
committed
一刷1823
1 parent b7f45b9 commit cbe316b

File tree

7 files changed

+49
-10
lines changed

7 files changed

+49
-10
lines changed

README.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12787,12 +12787,12 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
1278712787
//|Easy
1278812788
//|
1278912789

12790-
//|{counter:codes}
12791-
//|{leetcode_base_url}/find-the-winner-of-the-circular-game/[1823. Find the Winner of the Circular Game^]
12792-
//|{source_base_url}/_1823_FindTheWinnerOfTheCircularGame.java[Java]
12793-
//|{doc_base_url}/1823-find-the-winner-of-the-circular-game.adoc[题解]
12794-
//|Medium
12795-
//|
12790+
|{counter:codes}
12791+
|{leetcode_base_url}/find-the-winner-of-the-circular-game/[1823. Find the Winner of the Circular Game^]
12792+
|{source_base_url}/_1823_FindTheWinnerOfTheCircularGame.java[Java]
12793+
|{doc_base_url}/1823-find-the-winner-of-the-circular-game.adoc[题解]
12794+
|Medium
12795+
|
1279612796

1279712797
//|{counter:codes}
1279812798
//|{leetcode_base_url}/minimum-sideway-jumps/[1824. Minimum Sideway Jumps^]

docs/1823-find-the-winner-of-the-circular-game.adoc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ The rules of the game are as follows:
1818
Given the number of friends, `n`, and an integer `k`, return _the winner of the game_.
1919

2020

21-
<strong class="example">Example 1:*
22-
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/25/ic234-q2-ex11.png" style="width: 500px; height: 345px;" />
21+
*Example 1:*
22+
23+
image::images/1823-00.png[{image_attr}]
24+
2325
[subs="verbatim,quotes"]
2426
----
2527
*Input:* n = 5, k = 2
@@ -50,7 +52,7 @@ Given the number of friends, `n`, and an integer `k`, return _the winner of the
5052
*Constraints:*
5153

5254

53-
* `1 <= k <= n <= 500`
55+
* `1 \<= k \<= n \<= 500`
5456

5557

5658

@@ -62,6 +64,8 @@ Could you solve this problem in linear time with constant space?
6264

6365
== 思路分析
6466

67+
image::images/1823-01.png[{image_attr}]
68+
6569

6670
[[src-1823]]
6771
[tabs]
@@ -88,4 +92,7 @@ include::{sourcedir}/_1823_FindTheWinnerOfTheCircularGame.java[tag=answer]
8892

8993
== 参考资料
9094

95+
. https://leetcode.cn/problems/find-the-winner-of-the-circular-game/solutions/1463524/zhao-chu-you-xi-de-huo-sheng-zhe-by-leet-w2jd/?envType=study-plan-v2&envId=selected-coding-interview[1823. 找出游戏的获胜者 - 官方题解^]
96+
. https://leetcode.cn/problems/find-the-winner-of-the-circular-game/solutions/2362052/1823-zhao-chu-you-xi-de-huo-sheng-zhe-yu-tkst/?envType=study-plan-v2&envId=selected-coding-interview[1823. 找出游戏的获胜者 - 约瑟夫环,清晰图解^]
97+
9198

docs/images/1823-00.png

30.9 KB
Loading

docs/images/1823-01.png

157 KB
Loading

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3720,7 +3720,7 @@ include::1650-lowest-common-ancestor-of-a-binary-tree-iii.adoc[leveloffset=+1]
37203720

37213721
// include::1822-sign-of-the-product-of-an-array.adoc[leveloffset=+1]
37223722

3723-
// include::1823-find-the-winner-of-the-circular-game.adoc[leveloffset=+1]
3723+
include::1823-find-the-winner-of-the-circular-game.adoc[leveloffset=+1]
37243724

37253725
// include::1824-minimum-sideway-jumps.adoc[leveloffset=+1]
37263726

logbook/202406.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@
727727
|{doc_base_url}/0136-single-number.adoc[题解]
728728
|✅ 位运算,异或
729729

730+
|{counter:codes}
731+
|{leetcode_base_url}/find-the-winner-of-the-circular-game/[1823. Find the Winner of the Circular Game^]
732+
|{doc_base_url}/1823-find-the-winner-of-the-circular-game.adoc[题解]
733+
|❌ 约瑟夫环,使用队列出队入队来模拟计数,出队表示删除。妙!
734+
730735
|===
731736

732737
截止目前,本轮练习一共完成 {codes} 道题。
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.diguage.algo.leetcode;
2+
3+
import java.util.ArrayDeque;
4+
import java.util.Queue;
5+
6+
public class _1823_FindTheWinnerOfTheCircularGame {
7+
// tag::answer[]
8+
9+
/**
10+
* @author D瓜哥 · https://www.diguage.com
11+
* @since 2024-09-19 15:24:45
12+
*/
13+
public int findTheWinner(int n, int k) {
14+
Queue<Integer> queue = new ArrayDeque<>(n);
15+
for (int i = 1;i<=n;i++) {
16+
queue.offer(i);
17+
}
18+
while(queue.size()>1) {
19+
for (int i= 1;i<k;i++) {
20+
queue.offer(queue.poll());
21+
}
22+
queue.poll();
23+
}
24+
return queue.poll();
25+
}
26+
// end::answer[]
27+
}

0 commit comments

Comments
 (0)