Skip to content

Commit 5e4dc22

Browse files
authored
Sqrt(x)
1 parent 67aa2e7 commit 5e4dc22

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

69. Sqrt(x)/README.md

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

0 commit comments

Comments
 (0)