Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
First Non repeat char
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { String str = "aaa b bdd h aaa k "; char ch = firstNonRepeatedChar(str); } public static char firstNonRepeatedChar(String str) { Dictionary<char,int> dict = new Dictionary<char,int>(); dict.Add(str[0],1); for(int i=1; i< str.Length; i++) { if(dict.ContainsKey(str[i])) dict[str[i]]++; else dict.Add(str[i],1); } foreach (KeyValuePair<char,int> keypair in dict) { if(keypair.Value==1) { Console.Write(keypair.Key); return keypair.Key; break; } } return ' '; } } }
run
|
edit
|
history
|
help
0
Fórum ➡ Using Regex to insert "item" tags into the unique "list" tag of an XML data ♦
convert a string of numbers to a list then use a forEach to loop through the list
Intuit // C# // listing_4.10 (for..)
Get Bytecent Price in $USD
z x xc x
MostFrequent
30272 Program Ex5 if_else2_odd_even
Does string contain only digits
Generics Operator test
Output to get sum = 5 in given array of integers