Implementint sqrt(int x).
Compute and return the square root of x.
public class Solution {
public int sqrt(int x) {
long r = x;
while(r*r>x)
r = (r+x/r)/2;
return (int)r;
}
}
Implementint sqrt(int x).
Compute and return the square root of x.
public class Solution {
public int sqrt(int x) {
long r = x;
while(r*r>x)
r = (r+x/r)/2;
return (int)r;
}
}