首页 > 其他 > 详细

69. x 的平方根

时间:2021-04-17 17:41:18      阅读:28      评论:0      收藏:0      [点我收藏+]

牛顿迭代法

 1 package leetcode;
 2 
 3 public class demo_69 {
 4     public int mySqrt(int x) {
 5         long t=x;
 6         while(t*t>x) {
 7             t=(t+x/t)/2;
 8         }
 9         return (int)t;
10     }
11     public static void main(String[] args) {
12         // TODO Auto-generated method stub
13         demo_69 d69=new demo_69();
14         System.out.println(d69.mySqrt(5));
15     }
16 
17 }

 

69. x 的平方根

原文:https://www.cnblogs.com/Yshun/p/14669927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!