I'm trying to solve a challenge and the function must return a long integer and takes an int
and List<Long>
as parameters but i keep getting the following error:
Solution.java:32: error: incompatible types: possible lossy conversion from long to int
if (i >= coin) dp[i] += dp[i - coin];
I've tried different casting but it all comes back to this. My code is below:
public static long count(int n, List<Long> c) {
long[] dp = new long[n + 1];
dp[0] = 1;
for (long coin : c) {
for (long i = 1; i <= n; i++){
if (i >= coin) dp[i] += dp[i - coin];
}
}
return dp[n];
}
}