279. Perfect Squares
# Medium
Optimize solution:
Initialize all squares'
count
with-1
.Initialize all known squares, like cheating table. If
count[x] = -1
, then number x is not a square.Only the number who is not a square is needed to compute.
If this number can be decomposeted into two squares, then
count[x] = 2
. Ohterwise continue computing usingDP
method.
Last updated
Was this helpful?