当前位置:网站首页>Square root of X
Square root of X
2022-07-03 04:12:00 【Xiao Qi,.】
A nonnegative integer x, Calculate and return x The square root of .
Rounding off the decimal part of the result , Keep only integer parts and output .
for example :
Input :x=4
Output :2
Input :x=8
Output 2
Ideas : Use binary search to narrow the range until the final value is found and output
int mySqrt(int x){
int right=x;
int left=0;
int ans=0;
while(left<=right){
int mid=left+(right-left)/2; // Two points search
if ((double)mid * mid <= x) {
ans = mid;
left = mid + 1;// Update left border
} else {
right = mid - 1;// Update right border
}
}
return ans;
}
边栏推荐
- Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
- xrandr修改分辨率與刷新率
- MySQL create table
- leetcode:297. 二叉树的序列化与反序列化
- 有监督预训练!文本生成又一探索!
- 以两列的瀑布流为例,我们应该怎么构建每一列的数组
- Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis
- Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
- [no title] 2022 chlorination process examination content and free chlorination process examination questions
- [mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
猜你喜欢
"Final review" 16/32-bit microprocessor (8086) basic register
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode
Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences
用户体验五要素
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
Nodejs Foundation: shallow chat URL and querystring module
2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
Is pytorch open source?
2022 P cylinder filling examination content and P cylinder filling practice examination video
随机推荐
2022deepbrainchain biweekly report no. 104 (01.16-02.15)
学会pytorch能干什么?
基于Pytorch和RDKit的QSAR模型建立脚本
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
"Final review" 16/32-bit microprocessor (8086) basic register
用户体验五要素
ZIP文件的导出
MySQL field userid comma separated save by userid query
eth入门之简介
Social phobia of contemporary young people (II)
【刷题篇】 找出第 K 小的数对距离
How to connect WiFi with raspberry pie
Cnopendata China Customs Statistics
[set theory] set concept and relationship (set family | set family examples | multiple sets)
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
pytorch怎么下载?pytorch在哪里下载?
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
[no title] 2022 chlorination process examination content and free chlorination process examination questions
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
Appium automated testing framework