check if a number is perfect square number or not param num the number to be checked return true if number is square number otherwise false perfectsquare9 true perfectsquare16 true perfectsquare1 true perfectsquare0 true perfectsquare10 false check if a number is perfect square using binary search time complexity ologn space complexity o1 perfectsquarebinarysearch9 true perfectsquarebinarysearch16 true perfectsquarebinarysearch1 true perfectsquarebinarysearch0 true perfectsquarebinarysearch10 false perfectsquarebinarysearch1 false perfectsquarebinarysearch1 1 false perfectsquarebinarysearcha traceback most recent call last typeerror not supported between instances of int and str perfectsquarebinarysearchnone traceback most recent call last typeerror not supported between instances of int and nonetype perfectsquarebinarysearch traceback most recent call last typeerror not supported between instances of int and list check if a number is perfect square number or not param num the number to be checked return true if number is square number otherwise false perfect_square 9 true perfect_square 16 true perfect_square 1 true perfect_square 0 true perfect_square 10 false check if a number is perfect square using binary search time complexity o log n space complexity o 1 perfect_square_binary_search 9 true perfect_square_binary_search 16 true perfect_square_binary_search 1 true perfect_square_binary_search 0 true perfect_square_binary_search 10 false perfect_square_binary_search 1 false perfect_square_binary_search 1 1 false perfect_square_binary_search a traceback most recent call last typeerror not supported between instances of int and str perfect_square_binary_search none traceback most recent call last typeerror not supported between instances of int and nonetype perfect_square_binary_search traceback most recent call last typeerror not supported between instances of int and list
import math


def perfect_square(num: int) -> bool:
    
    return math.sqrt(num) * math.sqrt(num) == num


def perfect_square_binary_search(n: int) -> bool:
    
    left = 0
    right = n
    while left <= right:
        mid = (left + right) // 2
        if mid**2 == n:
            return True
        elif mid**2 > n:
            right = mid - 1
        else:
            left = mid + 1
    return False


if __name__ == "__main__":
    import doctest

    doctest.testmod()