找出给定的数字是否为完美平方?

public boolean isPerfectSquare(int n) {
    int l=1, r=n;
    if(r==l) return true;
    return searchBinary(l, r, n);
}
public boolean searchBinary(int l, int r, int n){
    if(r>l){
        int mid=l+(r-l)/2;
      //  System.out.println(l + " " + r + " " + mid + " " +n);
        if(mid*mid == n) return true;
        else if(mid*mid>n) return searchBinary(l, mid-1, n);
        else return searchBinary(mid+1, r, n);
    }
    return false;
}

My code is failing for n=808201

我不明白为什么它不起作用。这段代码对我来说不错。有什么建议么?

评论