You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Solution {
public:
int search(vector& A, int target) {
int L = 0, R = A.size();
while (L <= R) {
int M = (L + R) / 2;
if (A[M] == target) return M;
if (A[M] < target && A.size() != M + 1) L = M + 1;
else R = M - 1;
}
return -1;
}
};
The text was updated successfully, but these errors were encountered:
Thanks for reply. Yes, I know in general it won't fail, but when I review different solutions at that day, there is a weird testcase and that will fail at that day. That's why I added that condition to pass it. It seems like Leetcode already removed that testcase and now it's working fine again. Again, really appreciate your solutions here! If possible, you may try to add comments and explanation to help more people. :-)
class Solution {
public:
int search(vector& A, int target) {
int L = 0, R = A.size();
while (L <= R) {
int M = (L + R) / 2;
if (A[M] == target) return M;
if (A[M] < target && A.size() != M + 1) L = M + 1;
else R = M - 1;
}
return -1;
}
};
The text was updated successfully, but these errors were encountered: