Easy to Understand My c++ 0ms


  • 0
    L
    class Solution {
    public:
        bool isPerfectSquare(int num) {
            long low = 1;
            long high = num;
            while(low <= high){
                long mid = low + (high-low)/2;
                if(mid*mid == num)
                    return true;
                else if(mid* mid < num)
                    low = mid +1;
                else{
                    high = mid -1;
                }
            }
            return false;
        }
    };
    

Log in to reply
 

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