用list模拟离开回环的情况,直到剩下最后一个为止
import java.util.*; public class Solution { public int ysf (int n, int m) { List<Integer> list = new ArrayList<>(); for(int i = 1 ; i<= n ;i++){ list.add(i); } int begin = 0; while(list.size()!=1){ begin = (m+begin-1)%list.size(); list.remove(begin); } return list.get(0); } }