当前位置:网站首页>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;
}
边栏推荐
- 2.Elment Ui 日期选择器 格式化问题
- Openeuler kernel technology sharing - Issue 1 - kdump basic principle, use and case introduction
- 2021-11-11 standard thread library
- Installation and removal of MySQL under Windows
- STM32 general timer output PWM control steering gear
- QT setting suspension button
- LeetCode - 673. Number of longest increasing subsequences
- LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
- Blue Bridge Cup for migrant workers majoring in electronic information engineering
- Leetcode 300 longest ascending subsequence
猜你喜欢
LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
CV learning notes - edge extraction
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
Notes on C language learning of migrant workers majoring in electronic information engineering
Interruption system of 51 single chip microcomputer
For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
Yocto technology sharing phase IV: customize and add software package support
CV learning notes - feature extraction
Basic use and actual combat sharing of crash tool
Leetcode 300 longest ascending subsequence
随机推荐
Installation and removal of MySQL under Windows
Working mode of 80C51 Serial Port
2.Elment Ui 日期选择器 格式化问题
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
Vgg16 migration learning source code
CV learning notes - scale invariant feature transformation (SIFT)
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
Leetcode bit operation
CV learning notes - deep learning
Design of charging pile mqtt transplantation based on 4G EC20 module
is_ power_ of_ 2 judge whether it is a multiple of 2
My 4G smart charging pile gateway design and development related articles
LeetCode - 5 最长回文子串
CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
Opencv notes 17 template matching
03 fastjason solves circular references
Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip
My notes on intelligent charging pile development (II): overview of system hardware circuit design
LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
Yocto Technology Sharing Phase 4: Custom add package support