forked from c4fiber/java-onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem5.java
27 lines (22 loc) · 844 Bytes
/
Problem5.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
package onboarding;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.assertj.core.util.Arrays;
public class Problem5 {
public static List<Integer> solution(int money) {
List<Integer> answer = Collections.emptyList();
Problem5 problem5= new Problem5();
answer = problem5.categorize(money);
return answer;
} //solution
private List<Integer> categorize(int money){
List<Integer> wallet = new ArrayList<Integer>();
int[] moneyUnit = {1,10,50,100,500,1000,5000,10000,50000};
for(int i = moneyUnit.length-1; i > -1 ; i--){
if(i== moneyUnit.length-1) {wallet.add((money)/moneyUnit[i]);continue;}
wallet.add(money%(moneyUnit[i+1])/moneyUnit[i]);
}//for
return wallet;
} // categorize
}// end class