From 2cc22d0660897dae308ebd15a1f42b635bd439c5 Mon Sep 17 00:00:00 2001
From: Yucheng Hu
Date: Sat, 15 Dec 2018 14:03:48 -0500
Subject: [PATCH] =?UTF-8?q?LintCode=200425=20=E9=A2=98=E7=9B=AE=EF=BC=8C?=
=?UTF-8?q?=E9=87=87=E7=94=A8=E9=80=92=E5=BD=92=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../LintCode0425LetterCombinationsTest.java | 77 +++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java
diff --git a/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java b/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java
new file mode 100644
index 0000000000..8c6c281cb3
--- /dev/null
+++ b/src/test/java/com/ossez/lang/tutorial/tests/lintcode/LintCode0425LetterCombinationsTest.java
@@ -0,0 +1,77 @@
+package com.ossez.lang.tutorial.tests.lintcode;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * 425
+ *
+ *
+ *
+ * @author YuCheng
+ *
+ */
+public class LintCode0425LetterCombinationsTest {
+
+ private final static Logger logger = LoggerFactory.getLogger(LintCode0425LetterCombinationsTest.class);
+
+ /**
+ *
+ */
+ @Test
+ public void testMain() {
+ logger.debug("LetterCombinationsTest");
+ String digits = "23";
+
+ HashMap phoneKeyMap = new HashMap();
+ phoneKeyMap.put("0", "");
+ phoneKeyMap.put("1", "");
+ phoneKeyMap.put("2", "abc");
+ phoneKeyMap.put("3", "def");
+ phoneKeyMap.put("4", "ghi");
+ phoneKeyMap.put("5", "jkl");
+ phoneKeyMap.put("6", "mno");
+ phoneKeyMap.put("7", "pqrs");
+ phoneKeyMap.put("8", "tuv");
+ phoneKeyMap.put("9", "wxyz");
+
+ List retStatus = new ArrayList<>();
+
+ if (digits != null && digits.length() != 0) {
+ phoneRecursive(digits, retStatus, phoneKeyMap, "", 0);
+ }
+
+ System.out.println(retStatus);
+ }
+
+ /**
+ * phoneRecursive
+ *
+ * @param digits
+ * @param retStatus
+ * @param phoneKeyMap
+ * @param comb
+ * @param index
+ */
+ private void phoneRecursive(String digits, List retStatus, HashMap phoneKeyMap, String comb, int index) {
+ if (index == digits.length()) {
+ retStatus.add(comb);
+ return;
+ }
+
+ char pos = digits.charAt(index);
+ for (char c : ((String) phoneKeyMap.get(String.valueOf(pos))).toCharArray()) {
+ phoneRecursive(digits, retStatus, phoneKeyMap, comb + c, index + 1);
+ }
+ }
+}