当前位置:网站首页>69. Sqrt(x)x 的平方根
69. Sqrt(x)x 的平方根
2022-07-30 08:49:00 【DXB2021】
Given a non-negative integer x, compute and return the square root of x.
给你一个非负整数 x ,计算并返回 x 的 算术平方根 。
Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.
由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。
Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.
注意:不允许使用任何内置指数函数和算符,例如 pow(x, 0.5) 或者 x ** 0.5 。
Example 1:示例 1:
Input: x = 4
Output: 2
Example 2:示例 2:
Input: x = 8
Output: 2
Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
Constraints:提示:
0 <= x <=
- 1
C语言:
int mySqrt(int x){
long max=1;
while(max*max<=x)
{
max++;
}
return max-1;
}执行结果:通过
执行用时:24 ms, 在所有 C 提交中击败了10.23%的用户
内存消耗:5.5 MB, 在所有 C 提交中击败了45.56%的用户
通过测试用例:1017 / 1017
边栏推荐
- 新手必备!最全电路基础知识讲解
- 02-课程发布
- 代码随想录笔记_哈希_202 快乐数
- 都说FPGA高端,它到底能干啥?
- Windows 下安装 MySQL
- PyQt5快速开发与实战 7.4 事件处理机制入门 and 7.5 窗口数据传递
- 2022杭电多校第二场
- Activating data potential Amazon cloud technology reshapes cloud storage "family bucket"
- ant-design form form verification upload component (with personal packaged upload component)
- EMC过不了?都是PCB工程师的锅?
猜你喜欢
![MySQL [operator]](/img/dd/2bf6ccd731299dc405bc06e03e1550.png)
MySQL [operator]

Two solutions for Excel xlsx file not supported

积分专题笔记-曲线面积分三大公式

Using IN in MySQL will not go through index analysis and solutions

Windows 下安装 MySQL

Excel xlsx file not supported两种解决办法【杭州多测师】【杭州多测师_王sir】

统一异常处理导致ResponseBodyAdvice失效

STM8L_库函数-模板搭建

读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》

Kotlin 值类 - value class
随机推荐
SRAM与DRAM的区别
C语言经典练习题(3)——“汉诺塔(Hanoi)“
剖析SGI STL空间配置器(一 、辅助接口函数)
详解JVM垃圾回收
无法定位程序输入点ucrtbase.abort于动态链接库api-ms-win-crt-runtime-|1-1-0.dll上
信号完整性测试
最远点采样 — D-FPS与F-FPS
The difference between DDR, GDDR, QDR
利用R语言读取csv文件入一个数据框,然后查看各列的属性。
注解开发相关
函数式接口&Lambda表达式——简单应用笔记
els 方块向左移动
MySQL Explain 使用及参数详解
经历了这样一个阶段的发展之后,数字零售才能有新的进化
Detailed description of iperf3 parameter options
深入浅出零钱兑换问题——背包问题的套壳
七大排序之直接选择排序
一文理解分布式开发中的服务治理
积分简明笔记-第一类曲线积分的类型
研发转至FAE(现场应用工程师),是否远离技术了?有前途吗?