mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
17 lines
273 B
C++
17 lines
273 B
C++
class Solution {
|
|
public:
|
|
int mySqrt(int x) {
|
|
if (x == 0) {
|
|
return 0;
|
|
}
|
|
|
|
int times = 20;
|
|
double xi = x;
|
|
for (int i = 0; i < times; ++i) {
|
|
xi = (xi + x / xi) / 2;
|
|
}
|
|
|
|
return (int)xi;
|
|
}
|
|
};
|