I got accepted in a tricky way...The solution is not supposed to be correct


  • 0
    P

    The solution is supposed to be an O(n) algorithm.

    However, system accepted it...

    class Solution {
    public:
        int findMin(vector<int> &num) {
            int l = 0, r =  num.size()-1;
            while (l < r) {
                while (l < r && num[l] == num[r])
                    r--;
                if (num[l] < num[r])
                    return num[l];
                int mid = (l+r)>>1;
                if (num[mid] >= num[l]) {
                    if (num[mid+1] < num[l])
                        return num[mid+1];
                    l = mid+1;
                } else {
                    r = mid;
               }
            }
            return num[r];
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.