当前位置:网站首页>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语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
- Scenario based technology architecture process based on tidb - Theory
- The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
- UE source code reading [1]--- starting with problems delayed rendering in UE
- 享你所想。智创未来
- 强联通分量
- 最长公共子序列 - 动态规划
- 金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
猜你喜欢
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
Financial one account Hong Kong listed: market value of 6.3 billion HK $Ye wangchun said to be Keeping true and true, long - term work
How to deeply understand the design idea of "finite state machine"?
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
Recommendation number | what are interesting people looking at?
Getting started with rce
分享 12 个最常用的正则表达式,能解决你大部分问题
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
Simple process of penetration test
随机推荐
总量分析 核算方法和势方法 - 分摊分析
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
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
poi设置列的数据格式(有效)
C - Divisors of the Divisors of An Integer Gym - 102040C
The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
Lepton 无损压缩原理及性能分析
R language ggplot2 visual bar graph: visualize the bar graph through the two-color gradient color theme, and add label text for each bar (geom_text function)
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
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
清大科越冲刺科创板:年营收2亿 拟募资7.5亿
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
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
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
Laravel - model (new model and use model)
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
Use the word "new" to attract curious people
Tiflash compiler oriented automatic vectorization acceleration
Matlab learning 2022.7.4