I am working to solve this problem. I have to find the first nonrepeated character in a string.
For example, Input : “teeter” Output: r
I am going to first use HashTables :
class Program
{
static void Main()
{
var inputString = “teeter” ;
Hashtable hashtable = new Hashtable();
int numb = 1;
for (int i=0; i< inputString.length(); i++)
{
if (!hashtable.ContainsKey(hashtable[i]))
hashtable.Add(hashtable[i], numb);
else
hashtable[hashtable[i]] = hashtable[i].Value+ 1 ;
}
}
}
Can I solve this problem using LinQ:
numb = inputString.First(1 == inputString.Where(item =>
item == hashtable[i]).Count());
My questions are :
-I have to solve this problem using LINQ and using HashTables or Dictionaries. Does my solutions ture ?