[LeetCode]Sqrt(x)
2013-11-18 16:09
417 查看
Implement
Compute and return the square root of x.
思考:参考链接:/article/5111939.html
int sqrt(int x).
Compute and return the square root of x.
思考:参考链接:/article/5111939.html
class Solution { public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function double ans = x; while(abs(ans * ans - x) > 0.0001) { ans = (ans + x / ans) / 2; } return (int)ans; } };
相关文章推荐
- 浅谈ORACLE数据库闪回
- java获取shape文件面积
- centos 修改 设置系统时间
- 开发笔记:2013.11.18(二)
- ffmpeg 源代码简单分析 :av_read_frame()
- CString 和 string之间的转换
- 在ASP.NET中配置 html文件的访问验证
- tomcat配置问题
- 好的博客
- redis的内存分配问题
- 如何设置使 IIS 应用程序池使用 ASP.Net 3.5 而不是 2.0
- CentOS之间配置ssh免密码登录
- 香港美食攻略(7)——肥姐小食店★★★★
- 一个标准的JavaBean
- ASCII码 和 Unicode 小知识
- BP神经网络参数设置及实例
- jQuery中的 return false, e.preventDefault(), e.stopPropagation()的区别
- hdu1072 Nightmare(优先队列,BFS)
- binder
- HTML5之Web Worker