C# 把第一次出现的重复数字移动到最后
例如123455567123,变成123467123555。
View Code
static int[] MoveFirstDupNumToEnd(int[] intArr) { int[] result = new int[intArr.Length]; int dup = 0; int dupCount = 0; int x = 0; Hashtable ht = new Hashtable(intArr.Length); for (int i = 0; i < intArr.Length; i++) { if (ht[intArr[i]]==null) { ht.Add(intArr[i], 1); } else { dup = intArr[i]; break; } } for (int i = 0; i < intArr.Length; i++) { if (intArr[i] != dup) { result[x] = intArr[i]; x++; } else { dupCount++; } } while (dupCount>0) { result[x] = dup; x++; dupCount--; } return result; }