题解 | #平方和#
平方和
https://www.nowcoder.com/practice/6eade96172be4c8ba492747156481b9b
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param c int整型 * @return bool布尔型 */ bool square(int c) { // write code here int a = 1; int b = (int)sqrt((double)c); while(a <= b) { int tmp = a*a + b*b; if (tmp > c) { b--; } else if (tmp < c) { a++; } else { return true; } } return false; } };