diff --git a/problems/0017.电话号码的字母组合.md b/problems/0017.电话号码的字母组合.md index 90296efd..a77bce46 100644 --- a/problems/0017.电话号码的字母组合.md +++ b/problems/0017.电话号码的字母组合.md @@ -732,6 +732,38 @@ def backtracking(result, letter_map, digits, path, index) end end ``` +### C# +```C# +public class Solution +{ + public IList res = new List(); + public string s; + public string[] letterMap = new string[10] { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; + public IList 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); + } + } +} +```