367. Valid Perfect Square

Posted apanda009

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

367. Valid Perfect Square

367. Valid Perfect Square

367. Valid Perfect Square

leetcode 367. Valid Perfect Square

Leetcode 367. Valid Perfect Square

[leetcode] 367. Valid Perfect Square