当前位置:网站首页>LeetCode_ 69 (square root of x)
LeetCode_ 69 (square root of x)
2022-07-05 14:13:00 【***】
Title Description :
Give you a nonnegative integer x , Calculate and return x Of Arithmetical square root .
Because the return type is an integer , Results are retained only Integral part , The decimal part will be Give up .
Be careful : No built-in exponential functions and operators are allowed , for example pow(x, 0.5) perhaps x ** 0.5 .
Example 1:
Input :x = 4
Output :2
Example 2:
Input :x = 8
Output :2 explain :8 The arithmetic square root of is 2.82842…, Because the return type is an integer , The decimal part will be removed .
Tips :
0 <= x <= 231 - 1
class Solution {
public int mySqrt(int x) {
int ans=-1;
if(x==0)return 0;
for (int i = 1; i <=x; i++) {
if(x/i==i){
ans=i;
break;
}
else if((x/i)>i&&(x/(i+1))<(i+1)){
ans=i;
break;
}
}
return ans;
}
}
边栏推荐
- Postman简介、安装、入门使用方法详细攻略!
- Matlab learning 2022.7.4
- 2022 driller (drilling) examination question bank and simulation examination
- 基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
- 昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
- How to deeply understand the design idea of "finite state machine"?
- R language uses boxplot function in native package (basic import package, graphics) to visualize box plot
- SAS接口有什么优势特点
- 3W原则[通俗易懂]
- C - Divisors of the Divisors of An Integer Gym - 102040C
猜你喜欢
物联网应用技术专业是属于什么类
Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
Sqllab 1-6 exercise
如何深入理解“有限状态机”的设计思想?
UE source code reading [1]--- starting with problems delayed rendering in UE
What are the advantages and characteristics of SAS interface
为什么我认识的机械工程师都抱怨工资低?
常见问题之PHP——Fatal error: Allowed memory size of 314572800 bytes exhausted...
Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares
神经网络物联网未来现状和趋势及看法
随机推荐
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
用“新”字来吸引好奇的人群
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
LeetCode_2(两数相加)
After the microservice project is deployed, static resources and files uploaded to upload cannot be accessed. Solution
VC开发非MFC程序内存泄漏跟踪代码
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
物联网应用技术专业是属于什么类
Google EventBus 使用详解
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
鏈錶(簡單)
最简单不用证书也可以多开功能的方式
Brief introduction to revolutionary neural networks
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
R language uses boxplot function in native package (basic import package, graphics) to visualize box plot
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
Deep copy is hard