qrt(x) II
来源:互联网 发布:网络之重临巅峰txt下载 编辑:程序博客网 时间:2024/06/07 06:16
Implement double sqrt(double x)
and x >= 0
.
Compute and return the square root of x.
Notice
You do not care about the accuracy of the result, we will help you to output results.
Example
Given n
= 2
return 1.41421356
计算时,需要注意小数的计算,当开方的数是小数时,将end的默认值定义为0;
java
public class Solution { /* * @param x: a double * @return: the square root of x */ public double sqrt(double x) { // write your code here if (x < 0) { return -1; } double start = 0; double end = x; if (end < 1) { end = 1; } double mid = 0; double eps = 1e-12; while (end - start > eps) { mid = (end - start) / 2 + start; if (mid * mid > x) { end = mid; } else { start = mid; } } return start; }}
阅读全文
0 0
- qrt(x) II
- 面试宝典(PART II)位运算(II)X&(X-1)的几个运用
- Armadillo v4.x COPYMEM II Code Injection(2)
- MDI-II、MDI-X与双绞线线序
- Mule 2.x Getting Started Guide part II
- 2012年3月制作的DirectX(*.X)模型 II
- Part II. What’s New in Spring Framework 4.x
- ii
- ii
- ii
- II
- ii
- HUST 1214 Cubic-free numbers II(区间n=x^3*k的n的个数、枚举x容斥)
- [原创]深入理解C# 3.x的新特性(2):Extension Method - Part II
- linux device driver II 的模块程序在linux kernel 2.6.x 上的移植
- 三星 Galaxy S II GT-I9100 Android 4.0.x 固件 ROOT 教程
- Single Number && Single Number II && Factorial Trailing Zeroes && Pow(x, n) && Add Two Numbers
- 【EVB-335X-II试用体验】 上手试用与资源使用
- MAC 设置JAVA_HOME环境变量
- Codeforces 452 E. Segments Removal
- 数据流重定向和管道命令
- 科比退役原因-数据分析
- JAVA基础(一)---JAVA四大特性之一抽象
- qrt(x) II
- 硬盘检测工具CrystalDiskMark中文版|crystaldiskmark中文版V6.0.0.0下载|CrystalDiskMark硬盘检测工具
- list的erase
- 中国IT行业风投
- ajax图片上传
- 队列(FIFO)先进先出
- 建造者模式
- [最小权路径覆盖 & 网络流] BZOJ2324 :[ZJOI2011] 营救皮卡丘
- JDK下载与安装教程(最简单版)