Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean isPerfectSquare(int num) {
- long low = 0, high = num;
- while(low <= high) {
- long mid = low + (high - low)/2;
- //int product = mid * mid;
- // if(mid != 0 && product/mid != mid) {
- // high = mid - 1; // integer overflow;
- // continue;
- // }
- if(mid * mid == num) {
- return true;
- }
- if(mid * mid > num) {
- high = mid - 1;
- } else {
- low = mid + 1;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement