-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnotherCoinChangeProblem.java
43 lines (43 loc) · 1.06 KB
/
AnotherCoinChangeProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public static boolean makeChanges(int N, int K, int target, int[] coins) {
// code here
int one = K-1;
int two = 1;
int result = 0;
for(int i=0;i<N;)
{
result=coins[i]*one;
if(result>target)
{
one-=1;
two+=1;
if(one==0)
{
i++;
one=K-1;
}
continue;
}
for(int j=0;j<N;j++)
{
result = coins[i]*one + coins[j]*two;
// System.out.println(" result = "+ coins[i] + " * " + one + " + " + coins[j] + " * " + two);
// System.out.println(result);
if(result==target)
{
return true;
}
}
one-=1;
two+=1;
if(one!= 0)
{
i=0;
}
else{
i++;
}
}
return false;
}
}