当前位置:网站首页>LeetCode_69(x 的平方根 )
LeetCode_69(x 的平方根 )
2022-07-05 13:51:00 【***】
题目描述:
给你一个非负整数 x ,计算并返回 x 的 算术平方根 。
由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。
注意:不允许使用任何内置指数函数和算符,例如 pow(x, 0.5) 或者 x ** 0.5 。
示例 1:
输入:x = 4
输出:2
示例 2:
输入:x = 8
输出:2 解释:8 的算术平方根是 2.82842…, 由于返回类型是整数,小数部分将被舍去。
提示:
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;
}
}
边栏推荐
- 基于微信小程序的订餐系统
- Programmer growth Chapter 8: do a good job of testing
- Network security HSRP protocol
- The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
- How to deal with the Yellow Icon during the installation of wampserver
- 蓝桥杯学习2022.7.5(上午)
- Network security - Novice introduction
- Idea设置方法注释和类注释
- Rk3566 add LED
- French scholars: the explicability of counter attack under optimal transmission theory
猜你喜欢
![[cloud resources] what software is good for cloud resource security management? Why?](/img/c2/85d6b4a956afc99c2dc195a1ac3938.png)
[cloud resources] what software is good for cloud resource security management? Why?
![[public class preview]: basis and practice of video quality evaluation](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[public class preview]: basis and practice of video quality evaluation

stm32逆向入门

zabbix 监控

Intranet penetration tool NetApp

Mmseg - Mutli view time series data inspection and visualization

How to apply the updated fluent 3.0 to applet development

French scholars: the explicability of counter attack under optimal transmission theory

Usage, installation and use of TortoiseSVN

Idea remote debugging agent
随机推荐
Log4j utilization correlation
真正的缓存之王,Google Guava 只是弟弟
Jetpack compose introduction to mastery
Redis6 data type and operation summary
Usage, installation and use of TortoiseSVN
How to deal with the Yellow Icon during the installation of wampserver
Request + BS4 crawl Netease cloud music popular comments
Zhubo Huangyu: these spot gold investment skills are not really bad
53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
ELK 企业级日志分析系统
asp.net 读取txt文件
Set up a website with a sense of ceremony, and post it to the public 2/2 through the intranet
Kotlin collaboration uses coroutinecontext to implement the retry logic after a network request fails
[js] basic syntax - for loop
【华南理工大学】考研初试复试资料分享
TortoiseSVN使用情形、安装与使用
Controller in laravel framework
Simple PHP paging implementation
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
[MySQL usage Script] catch all MySQL time and date types and related operation functions (3)