# -Non-Constructible change ###### tags: `Easy`  求零錢堆中之最小不可得數目: 用了sort -> O(nlogn) time 想法: 從最小的數開始累積,如果遇到大於目前已累積數目的零錢,即遇到斷層-> 停止,如果沒就繼續加  ```cpp= #include <vector> using namespace std; int nonConstructibleChange(vector<int> coins) { // Write your code here. int cur_change = 0; sort(coins.begin(), coins.end()); for (auto x:coins){ if (x > cur_change + 1) return cur_change + 1; cur_change += x; } return cur_change + 1; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up