题目:开根号
eg.Input: 4 Output: 2
Input: 8 Output: 2 (因为8开根号是2.82842…,结果自小数部分截断,故最后结果取2)
注意:java中有定义好的开根号的方法以及double转int的方法。
class Solution {
public int mySqrt(int x) {
double n=Math.sqrt(x);
int i = (new Double(n)).intValue();
return i;
}
}