题目 :x的平方根
2015-08-19 18:35
253 查看
实现
您在真实的面试中是否遇到过这个题?
Yes
哪家公司问你的这个题?
Airbnb
Alibaba
Amazon Apple
Baidu Bloomberg
Cisco Dropbox
Ebay Facebook
Google Hulu
Intel Linkedin
Microsoft NetEase
Nvidia Oracle
Pinterest Snapchat
Tencent Twitter
Uber Xiaomi
Yahoo Yelp
Zenefits
感谢您的反馈
样例
sqrt(3) = 1
sqrt(4) = 2
sqrt(5) = 2
sqrt(10) = 3
挑战
O(log(x))
标签 Expand
二分法
数学
相关题目 Expand
1
(binary-search),(array)
容易 二分查找 29 %
class Solution {
/**
* @param x: An integer
* @return: The sqrt of x
*/
public int sqrt(int x) {
// write your code here
double r = 1.00;
if(x<0) return -1;
if(x==1) return 1;
while(Math.abs(r*r-x)>0.01){
r=(r+x/r)/2;
}
return (int)r;
}
}
int sqrt(int x)函数,计算并返回 x 的平方根。
您在真实的面试中是否遇到过这个题?
Yes
哪家公司问你的这个题?
Airbnb
Alibaba
Amazon Apple
Baidu Bloomberg
Cisco Dropbox
Ebay Facebook
Google Hulu
Intel Linkedin
Microsoft NetEase
Nvidia Oracle
Pinterest Snapchat
Tencent Twitter
Uber Xiaomi
Yahoo Yelp
Zenefits
感谢您的反馈
样例
sqrt(3) = 1
sqrt(4) = 2
sqrt(5) = 2
sqrt(10) = 3
挑战
O(log(x))
标签 Expand
二分法
数学
相关题目 Expand
1
(binary-search),(array)
容易 二分查找 29 %
class Solution {
/**
* @param x: An integer
* @return: The sqrt of x
*/
public int sqrt(int x) {
// write your code here
double r = 1.00;
if(x<0) return -1;
if(x==1) return 1;
while(Math.abs(r*r-x)>0.01){
r=(r+x/r)/2;
}
return (int)r;
}
}
相关文章推荐
- python常用的十进制、16进制、字符串、字节串之间的转换(长期更新帖)
- 活学活用wxPython -> 给你的wxPython程序一个稳固的基础
- nyoj1057 寻找最大数(三)
- 砾阳软件综合报表
- Spring+Quartz实现定时任务的详细配置方法
- 用Maven插件生成Mybatis代码
- 题目 :O(1)检测2的幂次
- poj1734Sightseeing Trip
- Android or iOS 运行 meteor App 屏幕一片空白 White screen的解决方法
- BroadcastReceiver使用方法及个人理解
- 反射
- latex如何输入正确的 双引号
- Hyper-V提供了三种网络模式
- Java 学习笔记(2) -- 数据类型
- 题目:Fizz Buzz
- 关于LCD Datesheet中 Color Depth的262K/65K的解释
- 安卓系统架构,Activity生命周期
- rsa互通密钥对生成及互通加解密(c#,java,php)
- 希尔排序
- Alcatraz 安装 及问题总结