当前位置:网站首页>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;
}
}
边栏推荐
- zabbix 监控
- ETCD数据库源码分析——集群间网络层客户端peerRt
- laravel-dompdf导出pdf,中文乱码问题解决
- Liar report query collection network PHP source code
- MySQL if else use case use
- Integer = = the comparison will unpack automatically. This variable cannot be assigned empty
- 2022建筑焊工(建筑特殊工种)特种作业证考试题库及在线模拟考试
- 53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
- Godson 2nd generation burn PMON and reload system
- redis6事务和锁机制
猜你喜欢

These 18 websites can make your page background cool

内网穿透工具 netapp

Rk3566 add LED

RK3566添加LED

Can graduate students not learn English? As long as the score of postgraduate entrance examination English or CET-6 is high!

Xampp configuring multiple items

Don't know these four caching modes, dare you say you understand caching?

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

这18个网站能让你的页面背景炫酷起来

Self built shooting range 2022
随机推荐
Data Lake (VII): Iceberg concept and review what is a data Lake
运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
:: ffff:192.168.31.101 what address is it?
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
::ffff:192.168.31.101 是一个什么地址?
leetcode 10. Regular expression matching regular expression matching (difficult)
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
【云资源】云资源安全管理用什么软件好?为什么?
锚点导航小demo
Matlab paper chart standard format output (dry goods)
[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
荐号 | 有趣的人都在看什么?
Network security - Novice introduction
Multi person cooperation project to see how many lines of code each person has written
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
蓝桥杯学习2022.7.5(上午)
Etcd database source code analysis -- rawnode simple package
Controller in laravel framework
asp.net 读取txt文件