Sqrt(x)
Implement int sqrt(int x)
.
Compute and return the square root of x.
1+3+5+7+...+(2n-1)=n*n
class Solution {
public:
int sqrt(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i=1;
while(x>=0){
x-=i;
i+=2;
}
return (i-1)/2-1;
}
};