[英]Java Writer error: The method write(char[], int, int) in the type Writer is not applicable for the arguments (int, double, int, String)
[英]error java The method combinationSum(int[], int, List<Integer>) 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);
}
你可以试试这个:
b.add(candidates[i]);
combinationSum(candidates,target-candidates[i],b));
首先将候选者添加到b
中,然后在递归调用中传递列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.