# LeetCode 367. Valid Perfect Square [367. Valid Perfect Square]([leetcode_url](https://leetcode.com/problems/valid-perfect-square/description/))(<font color=#00AF9B>Easy</font> 43.6%) <!-- (<font color=#00AF9B>Easy</font> 53.8%) (<font color=#FFB800>Medium</font> 39.6%) (<font color=#FF375F>Hard</font>) --> - 限制 : > 1 <= num <= $2^{31}$ - 1 - Solution 這題我的解法不好,但不是很想用牛頓法寫。 - 時間複雜度: $O(lgn)$ - 空間複雜度: $O(1)$ - 程式碼 ```c++= bool isPerfectSquare(int num) { if(num == 1) return true; long i = 1; while(i++) { if (i*i == num) { return true; } if(i*i > num) { return false; } } return false; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up