Implement int sqrt(int x)
.
Compute and return the square root of x.
using only integer division for the Newton method works
public int mySqrt(int x) { long r=x; while (r*r>x){ r=(r+x/r)/2; } return (int) r; }
Implement int sqrt(int x)
.
Compute and return the square root of x.
using only integer division for the Newton method works
public int mySqrt(int x) { long r=x; while (r*r>x){ r=(r+x/r)/2; } return (int) r; }
转载于:https://www.cnblogs.com/pulusite/p/7599432.html