Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java的数组的所有可能子序列_Java_Arrays - Fatal编程技术网

使用java的数组的所有可能子序列

使用java的数组的所有可能子序列,java,arrays,Java,Arrays,我打算找到数组的所有可能的子序列 我试着用两种不同的方法来做 1) 方法1 我用数组中的值创建一个字符串 // all possible subsequences - all possible elements found by eleiminating zero or more characters Public class StrManipulation{ public static void combinations(String suffix,String prefix){

我打算找到数组的所有可能的子序列

我试着用两种不同的方法来做

1) 方法1

我用数组中的值创建一个字符串

// all possible subsequences - all possible elements found by eleiminating zero or more characters

Public class StrManipulation{

public static void combinations(String suffix,String prefix){
    if(prefix.length()<0)return;
    System.out.println(suffix);
    for(int i=0;i<prefix.length();i++)
     combinations(suffix+prefix.charAt(i),prefix.substring(i+1,prefix.length()));
}

public static void main (String args[]){
    combinations("","12345");
    }
 }
//所有可能的子序列-通过删除零个或多个字符找到的所有可能元素
公共类标准化{
公共静态无效组合(字符串后缀、字符串前缀){

如果(prefix.length()这里有一个代码片段,其想法是:将元素添加到序列和之前的所有序列中,这是您想要的吗?如果序列已经存在,则不检查它

public List<List<Integer>> combinations(int[] arr) {
    List<List<Integer>> c = new ArrayList<List<Integer>>();
    List<Integer> l;
    for (int i = 0; i < arr.length; i++) {
      int k = c.size();
      for (int j = 0; j < k; j++) {
        l = new ArrayList<Integer>(c.get(j));
        l.add(new Integer(arr[i]));
        c.add(l);
      }
      l = new ArrayList<Integer>();
      l.add(new Integer(arr[i]));
      c.add(l);
    }
    return c;
}
公共列表组合(int[]arr){
列表c=新的ArrayList();
清单l;
对于(int i=0;i
这里是一个代码片段,其思想是:将元素添加到序列和之前的所有序列中,这是您想要的吗?如果序列已经存在,则不检查它

public List<List<Integer>> combinations(int[] arr) {
    List<List<Integer>> c = new ArrayList<List<Integer>>();
    List<Integer> l;
    for (int i = 0; i < arr.length; i++) {
      int k = c.size();
      for (int j = 0; j < k; j++) {
        l = new ArrayList<Integer>(c.get(j));
        l.add(new Integer(arr[i]));
        c.add(l);
      }
      l = new ArrayList<Integer>();
      l.add(new Integer(arr[i]));
      c.add(l);
    }
    return c;
}
公共列表组合(int[]arr){
列表c=新的ArrayList();
清单l;
对于(int i=0;i
您应该添加Java标记,因为它是您正在使用的语言。您应该添加Java标记,因为它是您正在使用的语言。