{3,1} 0 why my IDE get false while the result in leedcode is true


  • 0
    Q

    class Solution {
    public:
    bool search(int A[], int n, int target) {
    int low = 0;
    int high = n;

        while(low <= high)
        {
            
               int mid = (low + high)/2;
              
              if(A[mid] == target) return true;
              
              if(A[mid] > A[low])
              {
                    if(target >= A[low] && target < A[mid])
                        high =mid-1;
                    else 
                         low = mid+1;
              }
              else
              {
                     if(target > A[mid] && target < A[low])
                         low = mid+1;
                     else
                         high = mid-1;
              }
        }
    
        return false;
        
    }
    

    };


  • 0
    H
    This post is deleted!

Log in to reply
 

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