-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq16p20.java
More file actions
39 lines (34 loc) · 1.21 KB
/
Copy pathq16p20.java
File metadata and controls
39 lines (34 loc) · 1.21 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
import java.util.*;
public class q16p20{
public static void main(String[] args){
int[][] test = {{1,2,3},{4,5,6},{7,8,9}};
int[] inputA = {1,2,3};
int[] inputB = {4,5,6};
System.out.println(permutation(inputA, inputB).toString());
}
public static List<List<Integer>> permutation(int[] inputA, int[] inputB){
List<List<Integer>> lists = new ArrayList<>();
for(int i = 0; i<inputA.length; i++){
for(int j = 0; j<inputB.length; j++){
List<Integer> temp = new ArrayList<>();
temp.add(inputA[i]);
temp.add(inputB[j]);
lists.add(temp);
}
}
return lists;
}
void getValidWords(String number, int index, String prefix, HashSet<String> wordSet, ArrayList<String> results){
if(index == number.length() && wordSet.contains(prefix)){
results.add(prefix);
return;
}
char digit = number.charAt(index);
char[] letters = getT9Chars(digit);
if(letters != nul){
for(char letter: letters){
getValidWords(number, index+1, prefix+letter, wordSet, results);
}
}
}
}