```
class Solution {
public:
int sqrt(int x) {
double res = 1;
while (abs(res/2+x/(2*res) - res) > 0.1) {
res = res/2+x/(2*res);
}
if ((int)res*(int)res > x) res--;
return (int)res;
}
};
```

This is my code.