-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyPadCombination.java
More file actions
54 lines (41 loc) · 1.34 KB
/
Copy pathKeyPadCombination.java
File metadata and controls
54 lines (41 loc) · 1.34 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
package codingInterview.Recursion;
import java.util.ArrayList;
public class KeyPadCombination {
static String ms[] = {".", "abc", "def", "ghl", "jkl", "mno", "pqr", "st", "uvwx", "yz"};
public static void main(String s[]) {
//System.out.println(getAStrQA("179"););
getAStrQA("179", "");
//System.out.println(Integer.parseInt("147".charAt(0)+""));
}
public static ArrayList<String> getAStr(String s) {
if (s.length() == 0) {
ArrayList<String> al = new ArrayList<String>();
al.add("");
return al;
}
char ch = s.charAt(0);
String ros = s.substring(1);
int i = ch - '0';
ArrayList<String> rr = getAStr(ros);
ArrayList<String> my = new ArrayList<String>();
for (String ad : rr)
for (char sch : ms[i].toCharArray()) {
my.add(sch + ad);
}
return my;
}
public static void getAStrQA(String Ques, String ans) {//KBC
if (Ques.length() == 0) {
System.out.println(ans);
return;
}
char ch = Ques.charAt(0);
String ros = Ques.substring(1);
int i = ch - '0';
for (char chs : ms[i].toCharArray()) {
//getAStrQA(ros, ans);
getAStrQA(ros, chs + ans);
}
return;
}
}