leecode/backlog/633.sum-of-square-numbers.js
2020-05-22 18:17:19 +08:00

27 lines
486 B
JavaScript

/*
* @lc app=leetcode id=633 lang=javascript
*
* [633] Sum of Square Numbers
*/
/**
* @param {number} c
* @return {boolean}
*/
var judgeSquareSum = function(c) {
let start = 0;
let end = Math.floor(Math.sqrt(c));
while(start <= end) {
const res = Math.pow(start, 2) + Math.pow(end, 2);
if (res < c) {
start++;
} else if (res > c){
end--;
} else {
return true;
}
}
return false;
};