当前位置:网站首页>20220604数学:x的平方根
20220604数学:x的平方根
2022-07-03 09:20:00 【丿SeeYouAgain】
题目描述:给你一个非负整数 x
,计算并返回 x
的 算术平方根 。由于返回类型是整数,结果只保留 整数部分 ,小数部分将被 舍去 。
编码实现:
public int mySqrt(int x) {
int left = 0, right = x;
while (left <= right) {
int mid = (left + right) / 2;
long pow = (long) mid * mid;
if (pow > x) {
right = mid - 1;
} else if (pow < x) {
left = mid + 1;
} else {
return mid;
}
}
return right;
}
边栏推荐
- STM32 general timer output PWM control steering gear
- Exception handling of arm
- LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
- Windows下MySQL的安装和删除
- LeetCode - 919. Full binary tree inserter (array)
- Basic use and actual combat sharing of crash tool
- yocto 技術分享第四期:自定義增加軟件包支持
- 03 fastjason solves circular references
- CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
- LeetCode - 705 设计哈希集合(设计)
猜你喜欢
Adaptiveavgpool1d internal implementation
LeetCode - 919. 完全二叉树插入器 (数组)
Basic use and actual combat sharing of crash tool
Timer and counter of 51 single chip microcomputer
Swing transformer details-1
Swing transformer details-2
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
03 fastjason solves circular references
Notes on C language learning of migrant workers majoring in electronic information engineering
03 FastJson 解决循环引用
随机推荐
Replace the files under the folder with sed
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
el-table X轴方向(横向)滚动条默认滑到右边
Leetcode bit operation
About windows and layout
Opencv feature extraction sift
01仿B站项目业务架构
CV learning notes - deep learning
pycharm 无法引入自定义包
Yocto Technology Sharing Phase 4: Custom add package support
QT setting suspension button
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
Opencv interview guide
My notes on intelligent charging pile development (II): overview of system hardware circuit design
Crash工具基本使用及实战分享
51 MCU tmod and timer configuration
Opencv notes 17 template matching
Vscode markdown export PDF error
Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip