Day6. Namespace style
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_387._First_Unique_Character_in_a_String</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
387. First Unique Character in a String/Program.cs
Normal file
9
387. First Unique Character in a String/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _387._First_Unique_Character_in_a_String;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().FirstUniqChar("Leetcode"));
|
||||
}
|
||||
}
|
||||
20
387. First Unique Character in a String/Solution.cs
Normal file
20
387. First Unique Character in a String/Solution.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user