Day i do not know

This commit is contained in:
Electrominch
2022-10-18 00:45:31 +03:00
parent 01c5720116
commit 284b6ff10c
72 changed files with 1256 additions and 12 deletions

View File

@@ -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>

View 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")));
}
}

View 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;
}
}
}