当前位置:网站首页>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;
}
}
边栏推荐
- 基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
- POI set the data format of the column (valid)
- OSI and tcp/ip protocol cluster
- Getting started with rce
- 常见问题之PHP——Fatal error: Allowed memory size of 314572800 bytes exhausted...
- 别不服气。手机功能升级就是强
- Anchor navigation demo
- 鏈錶(簡單)
- Sqllab 1-6 exercise
- How to deeply understand the design idea of "finite state machine"?
猜你喜欢

Sqllab 1-6 exercise

Sorter evolution of ticdc 6.0 principle

What are the advantages and characteristics of SAS interface

神经网络物联网未来发展趋势怎么样

Scenario based technology architecture process based on tidb - Theory

Redis如何实现多可用区?

清大科越冲刺科创板:年营收2亿 拟募资7.5亿

魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問

TDengine 社区问题双周精选 | 第三期

Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
随机推荐
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
OSI and tcp/ip protocol cluster
04_solr7.3之solrJ7.3的使用
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
C - Divisors of the Divisors of An Integer Gym - 102040C
C语言中限定符的作用
强联通分量
判断变量是否为数组
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
01 、Solr7.3.1 在Win10平台下使用jetty的部署及配置
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
SAS接口有什么优势特点
神经网络物联网未来发展趋势怎么样
[buuctf.reverse] 152-154
Deep copy is hard
Scenario based technology architecture process based on tidb - Theory
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
Linked list (simple)
Laravel - view (new and output views)