当前位置:网站首页>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;
}
边栏推荐
- 03 FastJson 解决循环引用
- Opencv feature extraction sift
- Qcombox style settings
- Opencv notes 20 PCA
- Basic knowledge of communication interface
- 4G module designed by charging pile obtains signal strength and quality
- Leetcode bit operation
- pycharm 无法引入自定义包
- It is difficult to quantify the extent to which a single-chip computer can find a job
- Emballage automatique et déballage compris? Quel est le principe?
猜你喜欢

Working mode of 80C51 Serial Port

Leetcode interview question 17.20 Continuous median (large top pile + small top pile)

LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)

CV learning notes - clustering

ADS simulation design of class AB RF power amplifier

CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)

CV learning notes - BP neural network training example (including detailed calculation process and formula derivation)

2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)

Opencv feature extraction - hog

CV learning notes - reasoning and training
随机推荐
Synchronization control between tasks
Vscode markdown export PDF error
CV learning notes - image filter
STM32 running lantern experiment - library function version
Gpiof6, 7, 8 configuration
One click generate traffic password (exaggerated advertisement title)
Stm32f407 key interrupt
On the problem of reference assignment to reference
01仿B站项目业务架构
03 fastjason solves circular references
My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
STM32 general timer 1s delay to realize LED flashing
2020-08-23
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
LeetCode - 706 设计哈希映射(设计) *
Simulate mouse click
LeetCode - 919. Full binary tree inserter (array)
Crash工具基本使用及实战分享
Opencv histogram equalization
2.Elment Ui 日期选择器 格式化问题