69. Sqrt(x)
来源:互联网 发布:网络的个性化服务 编辑:程序博客网 时间:2024/06/05 02:33
使用二分法搜索最佳值
int mySqrt(int x) { long long left=0,right=x/2+1; while(left<=right){ long long mid=(left+right)/2; long long squa=mid*mid; if(squa==x) return mid; else if(squa<x) left=mid+1; else right=mid-1; } return right; }
牛顿迭代法求根
用牛顿法求sqrt
int mySqrt(int x) { double xn=0,xn1=1; while(abs(xn1-xn)>=1){ xn=xn1; xn1=(xn+x/xn)/2; } return int(xn1); }
阅读全文
0 0
- LeetCode 69. Sqrt(x)
- LeetCode 69.Sqrt(x)
- LeetCode --- 69. Sqrt(x)
- [Leetcode] 69. Sqrt(x)
- [leetcode] 69.Sqrt(x)
- 69.Sqrt(x)
- 69. Sqrt(x)
- Leetcode-69.Sqrt(x)
- leetcode--69.sqrt(x)
- 69. Sqrt(x)
- LeetCode 69. Sqrt(x)
- leetcode 69. Sqrt(x)
- 【LeetCode】69. Sqrt(x)
- 69. Sqrt(x) LeetCode
- 69. Sqrt(x)
- 69. Sqrt(x)
- [leetcode] 69. Sqrt(x)
- 69. Sqrt(x)
- 循环添加DOM元素
- jQuery监听回车键触发事件&keyCode值详细列表
- Hive-UDAF开发指南
- JAVA 打成jar包在linux运行
- NotePad++
- 69. Sqrt(x)
- OpenCv-绘画函数
- Spring任务定时调度<task:scheduled-tasks>cron参数详解
- unity3d 查找GameObject对象,FindObjectsOfType和FindObjectOfType 之遍历
- AndroidStudio JNI详细教程+Gradle3.0 以上 JNI 爬坑之旅
- 地图 路径规划
- 兼容
- 学习笔记-Jmeter之HTTP请求默认值
- 互联网时代的社会语言学:基于SNS的文本数据挖掘