Skip to content

Commit 10537cf

Browse files
adding 0069-sqrtx.c
1 parent 82e9776 commit 10537cf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: c/0069-sqrtx.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int mySqrt(int x){
2+
int l = 0;
3+
int r = x;
4+
5+
while(l <= r){
6+
long int m = (l + r) / 2;
7+
if(m * m == x){
8+
return m;
9+
}
10+
else if(m * m > x){
11+
r = m - 1;
12+
}
13+
else{
14+
l = m + 1;
15+
}
16+
}
17+
return r;
18+
}

0 commit comments

Comments
 (0)