Day6. Namespace style

This commit is contained in:
Electrominch
2022-10-07 16:36:27 +03:00
parent 62104da8f1
commit 5cae083979
51 changed files with 589 additions and 202 deletions

View File

@@ -0,0 +1,20 @@
namespace _387._First_Unique_Character_in_a_String;
public class Solution
{
public int FirstUniqChar(string s)
{
Dictionary<char, int> dic = new Dictionary<char, int>();
foreach (char ch in s)
{
if (dic.ContainsKey(ch))
dic[ch]++;
else
dic.Add(ch, 1);
}
for (int i = 0; i < s.Length; i++)
if (dic[s[i]] == 1)
return i;
return -1;
}
}