博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Leetcode] Sqrt(x)
阅读量:6986 次
发布时间:2019-06-27

本文共 270 字,大约阅读时间需要 1 分钟。

Implement int sqrt(int x).

Compute and return the square root of x.

牛顿迭代法, 碉堡了。

class Solution {public:    int sqrt(int x) {        double ans = x;        while (abs(ans * ans - x) > 0.0001) {            ans = (ans + x / ans) / 2;        }        return (int)ans;    }};

 

转载地址:http://drmpl.baihongyu.com/

你可能感兴趣的文章
总结!!!!!
查看>>
SpringBoot入门(三)——入口类解析
查看>>
Spring Boot系列——Spring Boot如何启动
查看>>
NIO之Charset类字符编码对象
查看>>
vue 父子组件传值的另外一种方式 provide inject
查看>>
关于ListBox在Grid中无法充满的问题
查看>>
【 Tomcat 】tomcat8.0 基本参数调优配置
查看>>
Android P的APP适配总结,让你快人一步
查看>>
Spring Boot 的 WEB 项目打包成的 JAR 包,打包成 docker 镜像基本步骤
查看>>
Table 'performance_schema.session_variables' doesn't exist
查看>>
WEB前端资源代码:PS记录
查看>>
WPF之托盘图标的设定
查看>>
查找字符是否存在列表中
查看>>
网络信息安全中最热门的果然是它
查看>>
C# -- 等待异步操作执行完成的方式 C# -- 使用委托 delegate 执行异步操作 JavaScript -- 原型:prototype的使用 DBHelper类连接数据库 MVC ...
查看>>
Git rebase使用
查看>>
Tetris in javascript[俄罗斯方块]
查看>>
Just Be
查看>>
一个感人的爱情故事(中英对照)
查看>>
【转载】大整数相乘
查看>>