-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 633. 平方数之和 | ||
|
||
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c 。 | ||
|
||
--- | ||
|
||
```js | ||
/** | ||
* @param {number} c | ||
* @return {boolean} | ||
*/ | ||
var judgeSquareSum = function(c) { | ||
for (var i = 0; i * i <= c; i ++) { | ||
var b = Math.sqrt(c - i * i) | ||
if (b === parseInt(b)) return true | ||
} | ||
return false | ||
}; | ||
|
||
``` |