首页 > 代码库 > 367. Valid Perfect Square

367. Valid Perfect Square

https://leetcode.com/problems/valid-perfect-square/#/solutions

public boolean isPerfectSquare(int num) {
        int beg = 1, end = num / 2 + 1;
        while (beg + 1 < end) {
            int mid = beg + (end - beg) / 2;
            if (num / mid == mid && num % mid == 0) {
                return true;
            } else if (num / mid < mid) {
                end = mid;
            } else {
                beg = mid;
            }
        }
        if (num / beg == beg && num % beg == beg || num / end == end && num % end == 0) {
            return true;
        } else {
            return false;
        }
    }

  

367. Valid Perfect Square