Skip to content

Instantly share code, notes, and snippets.

@pmatatias
Created May 10, 2020 08:56
Show Gist options
  • Select an option

  • Save pmatatias/73a75adc03dc019cc2b453da9fab57ee to your computer and use it in GitHub Desktop.

Select an option

Save pmatatias/73a75adc03dc019cc2b453da9fab57ee to your computer and use it in GitHub Desktop.
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