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
un poco de strings
D110
Range List for C#
for (int i= 2 ; i==5 ; i++)
N
Polygon Util
Сортировка массива
array print 2nd half first and 1 half later
a
Complex Variable Implementation in C#