""" 0367.1 - Solution 1 - Binary Search """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def isPerfectSquare(self, num: int) -> bool:
"""Valid Perfect Square Function"""
left, right = 1, num
while left <= right:
mid = left + (right - left) // 2
sq = mid * mid
if sq == num:
return True
elif sq > num:
right = mid - 1
else:
left = mid + 1
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().isPerfectSquare(16)) # Expected: True
print(Solution().isPerfectSquare(14)) # Expected: False
print(Solution().isPerfectSquare(1)) # Expected: True
print(Solution().isPerfectSquare(9)) # Expected: True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()