mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update0017.电话号码的字母组合,添加C#
This commit is contained in:
@ -732,6 +732,38 @@ def backtracking(result, letter_map, digits, path, index)
|
|||||||
end
|
end
|
||||||
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">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user