Newton's method in C++


  • 6
    X
    class Solution {
    public:
        int mySqrt(int x) {
            int y = 1;
            int n = x;
            while (n > y) {
                n = y +  (n - y) / 2;
                y = x / n;
            }
            return n;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.