Update0017.电话号码的字母组合,添加C#

This commit is contained in:
eeee0717
2023-12-13 09:45:51 +08:00
parent d3e61f36ab
commit c14df2f577

View File

@ -732,6 +732,38 @@ def backtracking(result, letter_map, digits, path, index)
end
end
```
### C#
```C#
public class Solution
{
public IList<string> res = new List<string>();
public string s;
public string[] letterMap = new string[10] { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
public IList<string> LetterCombinations(string digits)
{
if (digits.Length == 0)
return res;
BackTracking(digits, 0);
return res;
}
public void BackTracking(string digits, int index)
{
if (index == digits.Length)
{
res.Add(s);
return;
}
int digit = digits[index] - '0';
string letters = letterMap[digit];
for (int i = 0; i < letters.Length; i++)
{
s += letters[i];
BackTracking(digits, index + 1);
s = s.Substring(0, s.Length - 1);
}
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">