Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Complete the cutTheSticks function below.
- static int[] cutTheSticks(int[] arr) {
- List<Integer> result = new ArrayList<>();
- while(true){
- // 1. find min
- int mn = Integer.MAX_VALUE;
- for(int i = 0; i < arr.length; i++){
- if(arr[i] > 0)
- mn = Math.min(mn, arr[i]);
- }
- if(mn == Integer.MAX_VALUE)
- break;
- // 2. cur stick
- int count = 0;
- for(int i = 0; i < arr.length; i++){
- if(arr[i] > 0)
- count ++;
- arr[i] = arr[i] - mn;
- }
- // 3. append result
- result.add(count);
- }
- int[] res = new int[result.size()];
- for(int i = 0; i < result.size(); i++){
- res[i] = result.get(i);
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement