Skip to content

Commit 72b982f

Browse files
Create Sqrt
1 parent c986faa commit 72b982f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sqrt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
unsigned sq(unsigned i,unsigned n)
3+
{
4+
if(i*i==n) return i;
5+
if(i*i>n) return i-1;
6+
else
7+
return sq(++i,n);
8+
9+
}
10+
11+
public:
12+
int mySqrt(int x) {
13+
if(x==0) return 0;
14+
if(x==1) return 1;
15+
unsigned i=2;
16+
return sq(i,x);
17+
18+
}
19+
};

0 commit comments

Comments
 (0)