Leetcode Sqrt(x)
来源:互联网 发布:北京影视大数据公司 编辑:程序博客网 时间:2024/06/04 18:35
题意:求x的平方根的整数部分。
思路:二分查找。注意数据不要溢出。
class Solution {public: int mySqrt(int x) { int low = 0; int high = x; while(low != high) { double mid = ceil(low + (high - low) / 2.0); if(abs(mid * mid - x) < 1e-5) return mid; if(mid * mid < (double)x) low = (int)mid; else high = (int)mid - 1; } return low; }};
0 0
- LeetCode: Sqrt(x)
- LeetCode sqrt(x)
- [Leetcode] Sqrt(x)
- LeetCode :Sqrt(x)
- leetcode 53: Sqrt(x)
- [LeetCode] Sqrt(x)
- Leetcode 69 sqrt(x)
- [Leetcode] Sqrt(x)
- leetcode:Sqrt(x)
- 【leetcode】sqrt(int x)
- [LeetCode]Sqrt(x)
- [leetcode]Sqrt(x)
- LeetCode-Sqrt(x)
- [leetcode] Sqrt(x)
- [leetcode] Sqrt(x)
- LeetCode - Sqrt(x)
- leetcode之sqrt(x)
- LeetCode | Sqrt(x)
- 网络程序设计课程项目学习总结-SA16225018-曾龙飞
- HTML+CSS学习笔记三
- Go语言中的多核调度
- xz命令--Linux命令应用大词典729个命令解读
- repquota命令--Linux命令应用大词典729个命令解读
- Leetcode Sqrt(x)
- Oracle分页查询
- A good statement about CAP theory.
- Mac下通过Homebrew安装MySQL 和重置root登录密码
- ICMP报文分析(转)
- 19. Remove Nth Node From End of List 一道简单的双指针
- Palindrome Permutation II
- <caffe学习笔记> caffe训练日志输出
- Notes. Combination -- Batacktrack