llllmz

导航

367. 有效的完全平方数c

bool isPerfectSquare(int num) {
    if(num==1) return true;
    int head=0,tail=num-1;
    while(head<=tail){
        int mid=head+(tail-head)/2;
        long long temp=pow(mid,2);
        if(temp==num){
            return true;
        }else if(temp>num){
            tail=mid-1;
        }else{
            head=mid+1;
        }
    }
    return false;
}

 

posted on 2024-03-18 16:58  神奇的萝卜丝  阅读(8)  评论(0)    收藏  举报