This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Approach 1 | |
public void RemoveDupliates1() | |
{ | |
int[] k = new int[] { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 8, 8, 9, 9, 9 }; | |
int[] q = k.Distinct().ToArray(); | |
for (int i = 0; i <= q.Length - 1; i++) | |
{ | |
Response.Write(q[i]); | |
} | |
} | |
//Approach 2 | |
public void RemoveDupliates2() | |
{ | |
string[] sArray = { "a", "b", "b", "c", "c", "d", "e", "f", "f" }; | |
var sList = new ArrayList(); | |
for (int i = 0; i < sArray.Length; i++) | |
{ | |
if (sList.Contains(sArray[i]) == false) | |
{ | |
sList.Add(sArray[i]); | |
} | |
} | |
var sNew = sList.ToArray(); | |
for (int i = 0; i < sNew.Length; i++) | |
{ | |
Console.Write(sNew[i]); | |
} | |
} | |
//Approach 3 | |
public void RemoveDupliates3() | |
{ | |
int[] k = new int[] { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 8, 8, 9, 9, 9 }; | |
for (int i = 0; i < k.Length - 1; i++) | |
{ | |
if ((k[i] != k[i + 1])) | |
{ | |
Response.Write(k[i]); | |
} | |
if ((k[k.Length - 2] == k[k.Length - 1]) && (i == k.Length - 2)) | |
{ | |
Response.Write(k[i]); | |
} | |
if ((k[k.Length - 2] != k[k.Length - 1]) && (i == k.Length - 2)) | |
{ | |
Response.Write(k[i + 1]); | |
} | |
} | |
} |