mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
28 lines
436 B
Go
28 lines
436 B
Go
package main
|
|
|
|
func judgeSquareSum(c int) bool {
|
|
bsearch := func(left, right, target int64) bool {
|
|
for left <= right {
|
|
mid := left + (right-left)/2
|
|
|
|
if mid*mid == target {
|
|
return true
|
|
} else if mid*mid > target {
|
|
right = mid - 1
|
|
} else {
|
|
left = mid + 1
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
t := int64(c)
|
|
for a := int64(0); a*a <= t; a++ {
|
|
b := t - a*a
|
|
if bsearch(0, b, b) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|