当前位置:网站首页>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;
}
}
边栏推荐
- In addition to the root directory, other routes of laravel + xampp are 404 solutions
- 53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
- Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
- What about data leakage? " Watson k'7 moves to eliminate security threats
- 鏈錶(簡單)
- Network security HSRP protocol
- Redis6 transaction and locking mechanism
- 真正的缓存之王,Google Guava 只是弟弟
- zabbix 监控
- STM32 reverse entry
猜你喜欢

嵌入式软件架构设计-消息交互

:: ffff:192.168.31.101 what address is it?

基于微信小程序的订餐系统
![[public class preview]: basis and practice of video quality evaluation](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[public class preview]: basis and practice of video quality evaluation

Zibll theme external chain redirection go page beautification tutorial

Laravel framework operation error: no application encryption key has been specified

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

PHP basic syntax
![[server data recovery] a case of RAID5 data recovery stored in a brand of server](/img/04/c9bcf883d45a1de616c4e1b19885a5.png)
[server data recovery] a case of RAID5 data recovery stored in a brand of server

Convolutional Neural Networks简述
随机推荐
web3.eth. Filter related
Laravel generate entity
Kafaka log collection
Attack and defense world crypto WP
Attack and defense world web WP
Programmer growth Chapter 8: do a good job of testing
STM32 reverse entry
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
::ffff:192.168.31.101 是一个什么地址?
Jetpack compose introduction to mastery
Xampp configuring multiple items
[machine learning notes] how to solve over fitting and under fitting
Usage, installation and use of TortoiseSVN
Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
Redis6 data type and operation summary
53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
基于微信小程序的订餐系统
asp. Net read TXT file
[server data recovery] a case of RAID5 data recovery stored in a brand of server