当前位置:网站首页>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;
}
}
边栏推荐
- 魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
- The simplest way to open more functions without certificates
- 01. Solr7.3.1 deployment and configuration of jetty under win10 platform
- 基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
- 总量分析 核算方法和势方法 - 分摊分析
- 广发期货排名多少?网上办理广发期货开户安全可靠吗?
- 牛客网:拦截导弹
- 让秒杀狂欢更从容:大促背后的数据库(下篇)
- JS takes key and value from an array object to form a new object
- tidb-dm报警DM_sync_process_exists_with_error排查
猜你喜欢

What category does the Internet of things application technology major belong to

Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)

ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)

Tiflash compiler oriented automatic vectorization acceleration

tidb-dm报警DM_sync_process_exists_with_error排查

循环不变式

Tdengine biweekly selection of community issues | phase III

How to introduce devsecops into enterprises?

区间 - 左闭右开

如何将 DevSecOps 引入企业?
随机推荐
神经网络物联网未来现状和趋势及看法
What category does the Internet of things application technology major belong to
Postman简介、安装、入门使用方法详细攻略!
LeetCode_2(两数相加)
How to call the function mode of one hand and one machine
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
Tdengine biweekly selection of community issues | phase III
Assembly language
R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
微服务项目部署后,无法访问静态资源,无法访问到上传到upload中的文件,解决办法
Controller in laravel framework
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
关于Apache Mesos的一些想法
Google EventBus 使用详解
mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
Mysql database installation tutorial under Linux
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
Liste des liens (simple)
MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)