Home > Back-end > Java permutation and combination
Java permutation and combination
Time:11-19
Example: 1, 2, 3, a, b, After the permutation and combination, 1 a, 1 b, 2 a, 2 b, 3 a, 3 b, How to set up, only 1 and a combination, The results as follows: 1 a, 2 a, 2 b, 3 a, 3 b, Have to understand the great spirit of trouble can provide a train of thought or code post is too good, thank you very much,
CodePudding user response:
Similar to this? Public List Strs1 longestCommonPrefix (String [], String [] strs2, int a, int b) { List Result=new LinkedList<> (a); If (strs1. Length==0 | | strs2. Length==0) { Return the result. } for (int i=0; I{if (I==a) Result. The add (strs1 strs2 [I] + [b]); } else { For (int j=0; jResult. The add (strs1 strs2 [I] + [j]); } } } return result; }