当前位置:网站首页>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;
}
}
边栏推荐
- C - Divisors of the Divisors of An Integer Gym - 102040C
- The simplest way to open more functions without certificates
- 基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
- 鸿蒙第四次培训
- [buuctf.reverse] 152-154
- 清大科越冲刺科创板:年营收2亿 拟募资7.5亿
- 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
- 根据CronSequenceGenerator计算cron表达式的时间
- Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
- 故障分析 | MySQL 耗尽主机内存一例分析
猜你喜欢

How to deeply understand the design idea of "finite state machine"?

让秒杀狂欢更从容:大促背后的数据库(下篇)

软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】

明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿

Brief introduction to revolutionary neural networks

tidb-dm报警DM_sync_process_exists_with_error排查

治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东

为什么我认识的机械工程师都抱怨工资低?

常见问题之PHP——Fatal error: Allowed memory size of 314572800 bytes exhausted...

Xampp configuring multiple items
随机推荐
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功
Routing in laravel framework
Login interface code
R Language ggplot2 Visualization: visualize linegraph, using Legend in Theme function. Paramètre de position emplacement de la légende personnalisée
Sqllab 1-6 exercise
Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
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
动态规划
Use the word "new" to attract curious people
Hongmeng fourth training
Mysql database installation tutorial under Linux
R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
-Web direction attack and defense world
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
Blue Bridge Cup study 2022.7.5 (morning)
How to deeply understand the design idea of "finite state machine"?
LeetCode_69(x 的平方根 )
PHP5下WSDL,SOAP调用实现过程