Here is the code:
class Program
{
static void Main(string[] args)
{
Console.WriteLine(RemoveDuplicates("ajayreddy tutorials"));
}
public static string RemoveDuplicates(string s)
{
List<char> li = new List<char>();
bool foundDup=false;
for (int i = 0; i < s.Length; i++)
{
if (li.Count == 0)
{
li.Add(s[i]);
}
else
{
for (int j = 0; j < li.Count && j != i; j++)
{
if (s[i] == li[j])
{
foundDup = true;
}
}
if (!foundDup)
{
li.Add(s[i]);
}
else
{
foundDup = false;
}
}
}
return new string(li.ToArray());
}
}
This Solution is written by me and is not completely tested. Please comment if you found any alternative solutions or any enhancement to my solution.
Popular Posts
-
Here is the code: // => Brute Force Solution: O(m* n) static long arrayManipulation(int n, int[][] queries) { ...
-
Whatever it is one fine day everyone on this planet who are born have to die for sure. When you are close ones are with you, you wont know ...
-
HTML: <div class="outer-container"> <div class="inner-container"> <div class="t...
No comments:
Post a Comment