diff --git a/Easy/sqrtx/solution.cpp b/Easy/sqrtx/solution.cpp new file mode 100644 index 0000000..8828ccf --- /dev/null +++ b/Easy/sqrtx/solution.cpp @@ -0,0 +1,16 @@ +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; + } +};