Skip to content

Commit d596ca5

Browse files
committed
solution for sqrx problem
1 parent 4206deb commit d596ca5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

leetcode_Python/sqrx.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def mySqrt(self, x: int) -> int:
3+
begin = 0
4+
end = x
5+
6+
while begin <= x:
7+
mid = begin + (end - begin) // 2
8+
9+
if mid * mid <= x < (mid+1)*(mid+1):
10+
return mid
11+
elif x < mid * mid:
12+
end = mid - 1
13+
else:
14+
begin = mid + 1

0 commit comments

Comments
 (0)