Skip to content

Commit 4c2223b

Browse files
committed
add
1 parent d4f76f1 commit 4c2223b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

C++/sum-of-square-numbers.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(sqrt(c) * logc)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool judgeSquareSum(int c) {
7+
for (long long a = 0; a * a <= c; ++a) {
8+
auto b = static_cast<int>(sqrt(c - a * a));
9+
if (c - a * a == b * b) {
10+
return true;
11+
}
12+
}
13+
return false;
14+
}
15+
};
16+

0 commit comments

Comments
 (0)