简体   繁体   English

错误 java 方法组合Sum(int[], int, List<integer> ) 类型中的解决方案不适用于 arguments (int[], int, boolean)</integer>

[英]error java The method combinationSum(int[], int, List<Integer>) in the type Solution is not applicable for the arguments (int[], int, boolean)

/// to get all values that addup to the target. ///获取所有加到目标的值。 error The method combinationSum(int[], int, List) in the type Solution is not applicable for the arguments (int[], int, boolean)错误解决方案类型中的方法combinationSum(int[], int, List) 不适用于arguments (int[], int, boolean)

import java.util.*;
public class Solution {

    static List<Integer> b= new ArrayList<Integer>();
    static List<List<Integer>> c= new ArrayList<List<Integer>>();
    public static void combinationSum(int[] candidates, int target, List<Integer> b) 
    {   
        if(target==0)
        {
            c.add(b);
        }

        else {
        for(int i=0;i<candidates.length;i++)
        {   

//          else
//          {
          //  if( target < 0 )
          //  {
                //b.remove( b.size() - 1 );
          //  }
            if(target>0)
            {
                //b.add(candidates[i]);
                combinationSum(candidates,target-candidates[i],b.add(candidates[i]));
                //b.remove( b.size() - 1 );
            }
            //}
        }
        }
        //return;
    }

    public static void main(String[] args)
    {   
        int[] candidates= {2,3,5};
        int target=8;
        combinationSum(candidates,target,b);
        System.out.println(c);
    }

You can try this:你可以试试这个:

b.add(candidates[i]);
combinationSum(candidates,target-candidates[i],b));

First add the candidates to b and then pass the list in the recursive call.首先将候选者添加到b中,然后在递归调用中传递列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Writer 错误:Writer 类型中的方法 write(char[], int, int) 不适用于 arguments (int, double, int, String) - Java Writer error: The method write(char[], int, int) in the type Writer is not applicable for the arguments (int, double, int, String) LayoutInflater类型的方法inflate(int,ViewGroup,boolean)不适用于参数(int,int,boolean) - The method inflate(int, ViewGroup, boolean) in the type LayoutInflater is not applicable for the arguments (int, int, boolean) 类型中的方法不适用于参数(int) - The method in the type is not applicable for the arguments (int) 方法 sum(int, int, int, int) 不适用于参数 (int) - The method sum(int, int, int, int) is not applicable for the arguments (int) 如何修复错误:Map 类型中的 put(Integer, Integer) 方法<integer,integer>不适用于 arguments (int, String)</integer,integer> - How to fix error: The method put(Integer, Integer) in the type Map<Integer,Integer> is not applicable for the arguments (int, String) ArrayList 类型中的方法 set(int, Int)<int> 不适用于 arguments (int, int) 长度无法解析或不是字段</int> - The method set(int, Int) in the type ArrayList<Int> is not applicable for the arguments (int, int) length cannot be resolved or is not a field Integer类型的方法valueOf(String)不适用于参数(int) - The method valueOf(String) in the type Integer is not applicable for the arguments (int) TopScoreDocCollector 类型中的方法 create (int, int) 不能用于参数 (int, boolean) - Method create (int, int) in the type TopScoreDocCollector is not capable for the arguments (int, boolean) main类型的方法(double [])不适用于参数(int []) - The method (double[]) in the type main is not applicable for the arguments (int[]) ArrayBoss 类型中的方法 (int[]) 不适用于参数 () - The method (int[]) in the type ArrayBoss is not applicable for the arguments ()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM