Scribbling

LeetCode: 69. Sqrt(x) 본문

Computer Science/Coding Test

LeetCode: 69. Sqrt(x)

focalpoint 2021. 9. 26. 15:50

 

class Solution:
    def mySqrt(self, x: int) -> int:
        ret = 0
        l, r = 0, x
        while l <= r:
            mid = (l + r) // 2
            if mid * mid > x:
                r = mid - 1
            else:
                ret = max(ret, mid)
                l = mid + 1
        return ret

'Computer Science > Coding Test' 카테고리의 다른 글

LeetCode: 72. Edit Distance  (0) 2021.09.26
LeetCode: 71. Simplify Path  (0) 2021.09.26
LeetCode: 67. Add Binary  (0) 2021.09.26
LeetCode: 64. Minimum Path Sum  (0) 2021.09.24
LeetCode: 63. Unique Paths II  (0) 2021.09.24