special
牛顿迭代法
1 public class Solution { 2 public int sqrt(int x) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(x <= 0){ 6 return x; 7 } 8 double last = 0; 9 double cur = x; 10 while(Math.abs(cur - last) > 0.0001){ 11 last = cur; 12 cur = (cur + x / cur) / 2; 13 } 14 return (int)cur; 15 } 16 }