这道题目是这样的: 有一个list(eg.[1,0,0,0,0,1,0,0])每天更新,每个单元的新值看左右两边的邻居。如果左右一样就把当前值设置为0,不一样就设置为1。头和尾的前后分别当做是0。
比如说上面的例子就可以看成(0)[1,0,0,0,0,1,0,0](0)
实现如下
private static int[] FlipList(int[] list, int fliptime) {// TODO Auto-generated method stubif(list.length < 1)return list;int currentTime = 0;while(currentTime < fliptime){int[] newlist = new int[list.length];for(int i=0; i < list.length; i++){int last,next;if((i-1) < 0)last = 0;elselast = list[i-1];if((i+1) > (list.length-1))next = 0;elsenext = list[i+1];if(last == next){newlist[i] = 0;}elsenewlist[i] = 1;}list = newlist;currentTime++;}return list;}