> For the complete documentation index, see [llms.txt](https://hao-fu-1.gitbook.io/oj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hao-fu-1.gitbook.io/oj/math/sqrtx/valid-perfect-square.md).

# Valid Perfect Square

<https://leetcode.com/problems/valid-perfect-square/description/>

> Given a positive integer num, write a function which returns True if num is a perfect square else False.

## Thoughts

和sqrt(x)同理. 只是这次无论是二分还是牛顿法得到的最终结果不是直接返回, 而是与自身相乘看是否与num相等.

## Code

```
class Solution {
    public boolean isPerfectSquare(int num) {
        long r = num;
        while (r * r > num) {
            r = (r + num / r) / 2;
        }

        return r * r == num;
    }
}
```

## Analysis

时间复杂度未知.
