public boolean isPerfectSquare(int num) {
        if (num < 0) return false;
        if (num == 0) return true;
        long low = 1, high = num;
        while (low <= high) {
            long mid = (low + high) >> 1;
            if (mid * mid == num) return true;
            else if (mid * mid < num) low = mid + 1;
            else high = mid - 1;
        }
        return false;
    }