對整數開方java
思路:二分法,牛頓迭代法spa
java:code
牛頓迭代法blog
1 class Solution { 2 public int mySqrt(int x) { 3 long r = x; 4 while(r*r>x){ 5 r = (r + x/r)/2; 6 } 7 return (int)r; 8 } 9 }