Algorithms and Data Structures/Coding Practices

AlgoExpert Non-Constructible Change

brightlightkim 2022. 7. 10. 15:23

import java.util.*;

class Program {
  public int nonConstructibleChange(int[] coins) {
    if (coins.length == 0){
      return 1;
    }
    
    int minChange = 0;
    Arrays.sort(coins);

    for (int i=0; i < coins.length; i++){
      if(coins[i] > minChange + 1){
        break;
      }
      minChange += coins[i];
    }
    
    return minChange + 1;
  }
}

'Algorithms and Data Structures > Coding Practices' 카테고리의 다른 글

AlgoExpert Node Depths  (0) 2022.07.12
AlgoExpert Sorted Squared Array  (0) 2022.07.10
AlgoExpert Tournament Winner  (0) 2022.07.10
LeetCode 45. Jump Game II  (0) 2022.07.08
LeetCode 189. Rotate Array  (0) 2022.06.18