-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayGround.cs
More file actions
62 lines (52 loc) · 1.98 KB
/
PlayGround.cs
File metadata and controls
62 lines (52 loc) · 1.98 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LeetCode
{
[TestClass]
public class Solution
{
private List<string> letterList = new List<string> { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
public IList<string> LetterCombinations(string digits)
{
IList<string> letterCombination = new List<string>();
this.LetterCombinationHelper(digits, digits.Length, new char[digits.Length], 0, letterCombination);
return letterCombination;
}
public void LetterCombinationHelper(string digits, int len, char[] output, int count, IList<string> letterCombination)
{
if (len == 0)
return;
if (len == count)
{
letterCombination.Add(new string(output));
System.Diagnostics.Debug.WriteLine(new string (output));
return;
}
int index = int.Parse(digits[count].ToString());
if (index == 0 || index == 1)
{
return;
}
for (int i = 0; i < letterList[index].Length; i++)
{
output[count ] = letterList[index][i];
this.LetterCombinationHelper(digits, len, output, count + 1, letterCombination);
}
}
[TestMethod]
public void TestLetterCombination()
{
IList<string> expectedList = new List<string> { "ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf" };
IList<string> letterCombinationList = this.LetterCombinations("1");
Assert.AreEqual(expectedList.Count, letterCombinationList.Count);
foreach(string expectedStr in expectedList)
{
Assert.IsTrue(letterCombinationList.Contains<string>(expectedStr));
}
}
}
}