题解 | #袖珍计算器法#
求平方根
http://www.nowcoder.com/practice/09fbfb16140b40499951f55113f2166c
import java.util.*; public class Solution { /** * * @param x int整型 * @return int整型 */ public int sqrt (int x) { // write code here if (x == 0) { return 0; } int ans = (int) Math.exp(Math.log(x) * 0.5); return (ans + 1) * (ans + 1) <= x ? ans + 1 : ans; } }