633. Sum of Square Numbers
Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.
Example 1:
Input: c = 5
Output: true
Explanation: 1 * 1 + 2 * 2 = 5Example 2:
Input: c = 3
Output: falseExample 3:
Input: c = 4
Output: trueExample 4:
Input: c = 2
Output: trueExample 5:
Input: c = 1
Output: trueConstraints:
0 <= c <= 231 - 1
# @lc code=start
using LeetCode
function judge_square_sum(n::Int)
upper = isqrt(n)
i = 0
while i <= upper
ss = i ^ 2 + upper ^ 2
ss == n && return true
ss > n ? (upper -= 1) : (i += 1)
end
return false
end
# @lc code=endjudge_square_sum (generic function with 1 method)
This page was generated using DemoCards.jl and Literate.jl.