[英]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.