leetcode69: Sqrt(x)
2017-07-02 20:56
477 查看
要求:
Implement
Compute and return the square root of x.
注意:使用牛顿梯度法计算平方根,看百度百科或者维基百科
public int mySqrt(int x) {
if (x== 0)
return 0;
double sol = 1;
double res = 0;
while(sol - res!=0) {
res = sol;
sol = 0.5*(sol+x/sol);
}
return (int) sol;
}
Implement
int sqrt(int x).
Compute and return the square root of x.
注意:使用牛顿梯度法计算平方根,看百度百科或者维基百科
public int mySqrt(int x) {
if (x== 0)
return 0;
double sol = 1;
double res = 0;
while(sol - res!=0) {
res = sol;
sol = 0.5*(sol+x/sol);
}
return (int) sol;
}
相关文章推荐
- [Leetcode]@python 69. Sqrt(x)
- 69. Sqrt(x) LeetCode
- LeetCode(69) Sqrt(x)
- 【LeetCode】C# 69、Sqrt(x)
- [leetcode]69. Sqrt(x)
- leetcode 69: Sqrt(x)
- LeetCode---(69)Sqrt(x)
- (java)leetcode-69:Sqrt(x)
- 【leetcode】:leetcode 69 Sqrt(x) 牛顿迭代法
- 【一天一道LeetCode】#69. Sqrt(x)
- LeetCode 69 Sqrt(x)
- leetcode oj java 69. Sqrt(x)
- Leetcode 50. Pow(x, n) & 69. Sqrt(x)
- Leetcode 69. Sqrt(x)
- <LeetCode OJ> 69. Sqrt(x)
- LeetCode(69) Sqrt(x)
- leetcode 69 implement the sqrt(x)
- LeetCode 69. Sqrt(x)
- [Leetcode] 69. Sqrt(x)
- Leetcode 69. Sqrt(x) (Medium) (cpp)