Leetcode 367 Solution

This article provides solution to leetcode question 367 (valid-perfect-square)

https://leetcode.com/problems/valid-perfect-square

Solution

class Solution:
    def isPerfectSquare(self, num: int) -> bool:
        l = 0
        r = num

        while l < r:
            m = (l + r) // 2
            if m * m >= num:
                r = m
            else:
                l = m + 1

        return l * l == num