class Solution {
public boolean isPerfectSquare(int num) {
boolean flag = false;
int left = 0;
int right = num;
while(left <= right){
int mid = (left + right) / 2;
if((long)mid * mid == num){
flag = true;
break;
}else if((long)mid * mid < num){
left = mid + 1;
}else{
right = mid - 1;
}
}
return flag;
}
}
二分查找思想!!和上一篇Leetcode69题目思想一模一样,69题想了好久,这道题秒解,开心😊