share my java solution! similar to target sum!


  • 0
    T
    public class Solution {
        public boolean judgeSquareSum(int c) {
            if(c==0) return true;
            int i=0;
            int j=(int)Math.sqrt(c);
            
            while(i<=j){
                int num=i*i+j*j;
                if(num==c){
                    return true;
                }else if(num<c){
                    i++;
                }else{
                    j--;
                }
            }
            return false;
        }
    }
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.