开始是出列后就remove,后来发现太麻烦了。还是新建一个数组来记录状态
void solution(int n) {
ArrayList<Integer> baoshu = new ArrayList<Integer>();
int count = 0;
int out = 0;
boolean judge = true;
int j = 0;
boolean num[] = new boolean[n];
for (int i = 0; i < n; i++) {
baoshu.add(i + 1);
num[i] = true;
}
while (judge) {
if (num[j] == true) {
count++;
if (count == 3) {
count = 0;
System.out.println(baoshu.get(j));
// baoshu.remove(j);
// j--;
num[j] = false;
out++;
}
}
j++;
if (j == n)
j = 0;
if (out == n-1)
judge = false;
}
for(int k=0;k<n;k++)
if(num[k]==true)
System.out.println(baoshu.get(k));
}