Skip to content

Commit c2597a6

Browse files
authored
Create 0069-sqrtx.py
1 parent 816c3c0 commit c2597a6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: python/0069-sqrtx.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def mySqrt(self, x: int) -> int:
3+
l, r = 0, x
4+
while l <= r:
5+
mid = (l + r) // 2
6+
if mid * mid == x:
7+
return mid
8+
if mid * mid < x:
9+
l = mid + 1
10+
else:
11+
r = mid - 1
12+
return r

0 commit comments

Comments
 (0)