力扣-9.23-633

在这里插入图片描述

class Solution {
    
    
    public boolean judgeSquareSum(int c) {
    
    
        for(long a=0;a*a<=c;a++){
    
    
            double b=Math.sqrt(c-a*a);
            if(b==(int)b){
    
    
                return true;
            } 
        }
        return false;
    }
}
class Solution {
    
    
    public boolean judgeSquareSum(int c) {
    
    
        int low=0,high=(int)Math.sqrt(c);
        while(low<=high){
    
    
            if((low*low+high*high)<c){
    
    
                low++;
            }else if((low*low+high*high)>c){
    
    
                high--;
            }else{
    
    
                return true;
            }
        }
        return false;
    }
}

猜你喜欢

转载自blog.csdn.net/Desperate_gh/article/details/108753383
今日推荐