Here's the binary search approach:
function isPerfectSquare(num)
if num = 1 then
return true
left := 1
right := num
while left ≤ right
mid := left + (right - left) / 2
square := mid * mid
if square = num then
return true
else if square < num then
left := mid + 1
else
right := mid - 1
return false
Time: . Space: . You avoid overflow by using instead of .