-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0784-LetterCasePermutation.cs
42 lines (37 loc) · 1.27 KB
/
0784-LetterCasePermutation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//-----------------------------------------------------------------------------
// Runtime: 252ms
// Memory Usage: 34.6 MB
// Link: https://leetcode.com/submissions/detail/335014520/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0784_LetterCasePermutation
{
public IList<string> LetterCasePermutation(string S)
{
List<string> result = new List<string>();
BackTracking(S, "", result, 0);
return result;
}
public void BackTracking(string input, string current, List<string> result, int index)
{
if (current.Length == input.Length)
{
result.Add(new string(current.ToCharArray()));
return;
}
char ch = input[index];
if (char.IsDigit(ch))
{
current = string.Concat(current, ch);
BackTracking(input, current, result, index + 1);
}
else
{
BackTracking(input, current + char.ToLower(ch), result, index + 1);
BackTracking(input, current + char.ToUpper(ch), result, index + 1);
}
}
}
}