classSolution{public:booljudgeSquareSum(int c){long low=0;long high =long(sqrt(c));while(low<=high){long sum = low*low + high*high;if(sum==c)returntrue;if(sum<c)++low;if(sum>c)--high;}returnfalse;}};
Java
classSolution{publicbooleanjudgeSquareSum(int c){long low=0;long high =(long)Math.sqrt(c);while(low<=high){long sum = low*low + high*high;if(sum==c)returntrue;if(sum<c)++low;if(sum>c)--high;}returnfalse;}}