Standard binary search and a joke fucking bug I laugh loudly.....


  • -1

    What can you think if you meet the below sentence.

      while((1<<index)^2 <= x)  index++;
    

    What I want to mean is the square of the (1<<index)........

    Have you laugh loudly ......

    Here is my standard binary search implementation

    class Solution {
    public:
        int mySqrt(int x) {
            int start=0, end=INT_MAX;
            while(end-start>1){
                int mid=(start+end)/2;
                if(mid>x/mid) end=mid;
                else  start=mid;
            }
            return start;
        }
    };

Log in to reply
 

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