Day i do not know
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_784._Letter_Case_Permutation</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
784. Letter Case Permutation/Program.cs
Normal file
9
784. Letter Case Permutation/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _784._Letter_Case_Permutation;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(String.Join(" ", new Solution().LetterCasePermutation("hello")));
|
||||
}
|
||||
}
|
||||
28
784. Letter Case Permutation/Solution.cs
Normal file
28
784. Letter Case Permutation/Solution.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
|
||||
namespace _784._Letter_Case_Permutation;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public IList<string> LetterCasePermutation(string s)
|
||||
{
|
||||
HashSet<string> set = new HashSet<string>();
|
||||
StringBuilder sb = new StringBuilder(s);
|
||||
for (int i = 0; i < Math.Pow(2, s.Length); i++)
|
||||
{
|
||||
UppercasePerMask(sb, i);
|
||||
set.Add(sb.ToString());
|
||||
}
|
||||
return set.ToList();
|
||||
}
|
||||
|
||||
private void UppercasePerMask(StringBuilder sb, int mask)
|
||||
{
|
||||
for (int i = sb.Length - 1; i >= 0; i--)
|
||||
{
|
||||
if (char.IsLetter(sb[i]))
|
||||
sb[i] = mask % 2 == 1 ? char.ToUpper(sb[i]) : char.ToLower(sb[i]);
|
||||
mask >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user