Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit bce5ba7

Browse files
Added solution to 0069_sqrt(x)
1 parent e33df6a commit bce5ba7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

LeetCode/0069 _ Sqrt(x).py

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

0 commit comments

Comments
 (0)