(無序)數組去重,雖然不是比較優的算法,可是我的感受還能夠

public string[] deleteRepeat( string[] mobile) {c++

List d_index = new List();//重複數據的索引放在這裏索引

List a_index = new List();//非重複數據的索引放在這裏string

for (int i = 0; i < mobile.Length-1; i++) {mobile

int c = -1;//其實這裏用bool更好一點foreach

for (int k = 0; k < d_index.Count; k++) {List

if (i == d_index[k]) {數據

c++; continue;//判重co

}let

}new

if (c > -1)

continue;

a_index.Add(i);//在前面確保無重複的狀況下,把索引添加到list裏面

for (int j = i + 1; j < mobile.Length; j++) {

if (mobile[i].Equals(mobile[j])) {

d_index.Add(j);//發現重複,把索引添加到list裏面

}

}

}

string[] res_mobile = new string[a_index.Count];

int count = 0;

foreach (int i in a_index) {

res_mobile[count] = mobile[i]; count++;

}

return res_mobile;//返回的非重複數據

}

相關文章
相關標籤/搜索