simple c++ code


  • 0
    A
    class Solution {
    public:
    	bool judgeSquareSum(int c) {
    		int sqr = (int) sqrt(1.0 * c);
    		for (int i = sqr; i > sqr / 2; --i) {
    			int j = (int) sqrt(1.0 * c - i * i);
    			if (j * j + i * i == c) {
    				return 1;
    			}
    		}
    		return 0;
    	}
    };
    

Log in to reply
 

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