Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created February 11, 2018 14:11
Show Gist options
  • Save s4553711/537b4dd62debf6ff2a39f4f5eab4a489 to your computer and use it in GitHub Desktop.
Save s4553711/537b4dd62debf6ff2a39f4f5eab4a489 to your computer and use it in GitHub Desktop.
class Solution {
public:
bool judgeSquareSum(int c) {
int half = (c >> 1), sb, b;
for(int a = 0; a * a <= half; a++) {
sb = c - a * a;
b = sqrt(sb);
if (b * b == sb) return true;
}
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment