Skip to content

LC 0069 [E] Sqrt(x)

Code with Senpai edited this page Jun 28, 2022 · 1 revision
class Solution(object):
    def mySqrt(self, x):
        l, r = 0, x
        while l <= r:
            m = (l + r) // 2
            if m**2 <= x < (m+1)**2:
                return m
            elif x < m**2:
                r = m - 1
            else:
                l = m + 1
Clone this wiki locally