Skip to content

Commit 8fa6345

Browse files
authored
Merge pull request vJechsmayr#193 from pranjalkumar153/pranjalkumar153
Added solution to 0069_sqrt(x)
2 parents e4e7e3b + bce5ba7 commit 8fa6345

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)