I’m struggling to adapt the code found by codaddict proposed here to solve
this simple variant of the problem. Anyone has an idea?
I’m struggling to adapt the code found by codaddict proposed here to solve this
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You take his algorithm, and return
highinstead of-1. IfX[high]is smaller than your target, take the next item instead. Ifhighis equal to your array size, there is no such index.Michael Anderson is right about how the algorithm you pointed to was written, but it is easy to adapt.
However, this is equivalent to the following in C++: