VV Easy C++ soln (works)


#1
int Solution::sqrt(int A) {
    if(A == 0 || A == 1) return A;
    if(A == 2 || A == 3) return 1;
    long long low = 0, hi = A/2;
    long long mid = low + (hi-low)/2;
    
    while(low <= hi){
        long long mid = low + (hi-low)/2;
        // if(mid == A/mid) return mid;
        if(mid*mid <= A && (mid+1)*(mid+1) > A) return mid;
        else if(mid > A / mid) hi = mid-1;
        else low = mid+1;
    }
    return (int)mid;
}

#2

Thanks for the help.


#3

You are very welcome :wink: