Skip to content

Commit 1162590

Browse files
authored
Merge pull request #2632 from TheHong/py-0069
Create 0069-sqrtx.py
2 parents 816c3c0 + c2597a6 commit 1162590

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)