111,130
社区成员
发帖
与我相关
我的任务
分享 int[] list=new int[]{1,1,1,1,1,2,2,2,3,3,4,6,6,6,7,7,7,7,7,7,7};
ArrayList array=new ArrayList(list);
ArrayList result=new ArrayList();
int temp=-1,pos=0;
while(array.Count>0)
{
if(temp!=(int)array[pos])
{
temp=(int)array[pos];
result.Add(temp);
array.RemoveAt(pos);
}
else
{
pos++;
if((int)array[0]==(int)array[array.Count-1])
{
result.AddRange(array);
array.Clear();
}
}
if(pos==array.Count)pos=0;
}