解题思路
维护一个List看作是一个圆圈,并将每次被点到的小朋友编号移除
用location表示当前小朋友位置,如果location==List.size(),那么需要将location变回为0
代码
if (n<=0) return -1;
int ans = 0;
List<Integer> child = new ArrayList<>();
for (int i=0;i<n;i++){
child.add(i);
}
int location = 0;//用来记录当前报数小孩的位置
while (child.size()!=1){
for (int i=1;i<m;i++){
location++;
if (location==child.size()) location=0;
}
child.remove(location);
if (location==child.size()) location=0;
}
return child.get(0);
}