/**
* 双指针
* 一个读取 一个写入
*/
public static void magicalString(int n) {
//边界
if(n<=0){
return ;
}
int[] ints = new int[n];
int next = 1;
ints[0] = 1;
ints[1] = 2;
boolean one = false;
for (int i = 1; i < n; i++) {
//根据当前数值 计算出写入的index ,value ,num
int num = ints[i];
int value = one?1:2;
for (int j = 0; j < num; j++) {
if (next > n - 1)
break;
ints[next] = value;
next++;
}
one = !one;
}
System.out.println("n = [" + Arrays.toString(ints) + "]");
}