当前位置:网站首页>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;
}
}
边栏推荐
- R语言使用ggplot2包的geom_histogram函数可视化直方图(histogram plot)
- 最长公共子序列 - 动态规划
- 微服务项目部署后,无法访问静态资源,无法访问到上传到upload中的文件,解决办法
- Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
- 汇编语言 assembly language
- Fault analysis | analysis of an example of MySQL running out of host memory
- Controller in laravel framework
- Laravel - view (new and output views)
- R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
- 常见问题之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
What is the future development trend of neural network Internet of things
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
Tiflash compiler oriented automatic vectorization acceleration
Introduction, installation, introduction and detailed introduction to postman!
区间 - 左闭右开
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
循环不变式
Deep copy is hard
Recommendation number | what are interesting people looking at?
随机推荐
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to each vari
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
Detailed explanation of SSH password free login
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
用“新”字来吸引好奇的人群
Show strength. In this way, the mobile phone will not be difficult to move forward
汇编语言 assembly language
mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
清大科越冲刺科创板:年营收2亿 拟募资7.5亿
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
Geom of R language using ggplot2 package_ Histogram function visual histogram (histogram plot)
R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
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
区间 - 左闭右开
JS takes key and value from an array object to form a new object
LeetCode_67(二进制求和)
Leetcode array question brushing notes
R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
R Language ggplot2 Visualization: visualize linegraph, using Legend in Theme function. Paramètre de position emplacement de la légende personnalisée