Problem description :( Joseph Ring )

sample input :

The code is as follows : Using linked list simulation
import java.util.Scanner; public class FindTheWinner { // Find the winner of the game //1 <= k <=
n <= 500 class Node{ int data; Node next; public Node(int data) { =
data; } } public int findTheWinner(int n, int k) {// Use the circular list to solve the problem if (k==1) return n
; Node first=new Node(1); Node p=first; for (int i = 2; i <=n ; i++) {
new Node(i);; };// end to end Node p1=first; Node pre=null; int
cnt=1; while (p1!=pre){ pre=p1;; cnt++; if (cnt==k){
;// delete p1 Node referred to cnt=1;;// take p1 Point to next node } } return; } public static
void main(String[] args) { Scanner scanner=new Scanner(; int n=scanner
.nextInt(); int k=scanner.nextInt(); FindTheWinner findTheWinner=new
FindTheWinner(); System.out.println(findTheWinner.findTheWinner(n,k)); } }
The operation results are as follows :

©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage Python Study notes ( one )evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possibleRISC-V_GD32VF103-TIMER0 timer interrupt java Array subscript variable _Java Basic grammar : array be based on stm32 Control four-wheel trolley motor drive ( one ) be based on redis Design of liking function Software engineering career planning mysql Query random data by conditions _MySQL Random query of several qualified records centos7 install RabbitMq