Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #2

Open
ptoledor opened this issue Aug 20, 2020 · 2 comments
Open

Question #2

ptoledor opened this issue Aug 20, 2020 · 2 comments

Comments

@ptoledor
Copy link

for(int i=0; i<nc; i++){
    if(**nc-1 == i** || curSum+coins[i] < coins[i+1]){
        curSum += coins[i];
        res++;
    }
}   
cout << res << endl;

}

whats the logic behing "nc-1 == i"
thanks

@KHvic
Copy link
Owner

KHvic commented Aug 21, 2020

it's simply checking the last item of the vector/array.

@ptoledor
Copy link
Author

ptoledor commented Aug 21, 2020

thanks a lot, I was stuck on why you always add a coin in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants