Leetcode 367. Valid Perfect Square - 简书

bool isPerfectSquare(int num) {

    int left = 1;
    int right = num / 2;
    int mid;
    while(left <= right){
        mid = (left + right) >> 1;
        
        if(mid * mid >= num || mid >= 46341){
            right = mid - 1;
        }else{
            left = mid + 1;
        }   
    }
    return left * left == num;
    
}

46341 = sort(INT_MAX)

推荐阅读更多精彩内容