思路:
熟悉工具类的都知道,Math里面有个floor就是向下取整的而且参数为double类型,而int转double是没问题的,然后向下取整后,double类型强转回int也不会有精度缺失了。。。
public int mysqrt (int x) {
// write code here
double temp = Math.mysqrt(x);
int res = (int)Math.floor(temp);
return res;
}阿巴阿巴阿巴

京公网安备 11010502036488号