LeetCode 633. Sum of Square Numbers — JavaScript
Published in
Jun 17, 2024
領500元現金了嗎? 點選我的連結成功開樂天帳戶+登入樂天網銀APP,拿500元現金! 樂天帳戶好康在這 : · 使用行動支付5次,享次月活儲年息1.35%存額無上限 · VIP享每月免費跨提/轉共16次 · 提領日幣手續費優惠8次/月 (推薦序號: JGONGL)
https://www.rakuten-bank.com.tw/s/R775
var judgeSquareSum = function(c) {
const sqrt = Math.floor(Math.sqrt(c))
for(let i=sqrt; i>=0;i--) {
let tmp = c
if(Math.sqrt(tmp-i*i) % 1 === 0) return true
}
return false
};
0 is the square of 0 and 0. if Math.sqrt(n)%1===0 means n is perfect square