Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
FirstNonRepeatCharOfString
//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
Please
log in
to post a comment.
Anq Calc
comb sort
Possible Maximum
Read XML nodes into Data Dictionary
recursion
StringBuilder
Cotton Farm 0.0.2.02
lasses, properties, methods, ling begining
Delegate In C#
Sample Linq Test
Please log in to post a comment.