Created
May 10, 2020 08:56
-
-
Save pmatatias/73a75adc03dc019cc2b453da9fab57ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public boolean isPerfectSquare(int num) { | |
| int p = 1; | |
| int r = num; | |
| while (p <= r) { | |
| int x = p - (p - r) / 2; | |
| if (x * x == num) return true; | |
| else if (x * x < num) p = x + 1; | |
| else r = x - 1; | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment