Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NonRepeatingString
//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) { //nonRepeating("abcab"); // should return 'c' //nonRepeating("abab"); // should return null //nonRepeating("aabbbc"); // should return 'c' //nonRepeating("aabbdbc"); // should return 'd' Console.WriteLine(nonRepeating("aabbdbc")); } private static string nonRepeating(string input){ if( input == null ) return null; var charCount = new Dictionary<char, int>(); var charArray = input.ToCharArray(); for ( int i = 0; i < charArray.Length; i++ ) { if( charCount.ContainsKey(charArray[i]) ) charCount[charArray[i]] += 1; else charCount[charArray[i]] = 1; } foreach ( char c in input ) { if (charCount[c] == 1) return c.ToString(); } return null; } } }
run
|
edit
|
history
|
help
0
ConcurrentQueue<T>
Lab7
Demonstration await Control returned to the Caller
regex: rozważania nad powielaniem grup za pomocą kwantyfikatora
biswa
Whats Wrong in Here ?
Counter-Strike Global Offensive Steam
Mintra url string replace
Fórum ➡ GroupJoin ➡ Join ➡ Easily ‼
Remove Duplicate characters from String