From c14df2f5779314078744090b62d9745f34de1d24 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 13 Dec 2023 09:45:51 +0800 Subject: [PATCH] =?UTF-8?q?Update0017.=E7=94=B5=E8=AF=9D=E5=8F=B7=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AF=8D=E7=BB=84=E5=90=88=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0017.电话号码的字母组合.md | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) 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); + } + } +} +```