当前位置:网站首页>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 NVIC interrupt priority management
- Adaptiveavgpool1d internal implementation
- LeetCode - 919. Full binary tree inserter (array)
- is_ power_ of_ 2 judge whether it is a multiple of 2
- (1) 什么是Lambda表达式
- Swing transformer details-2
- Basic knowledge of communication interface
- Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
- Stm32f407 key interrupt
- 4G module initialization of charge point design
猜你喜欢

Opencv feature extraction sift

Leetcode 300 longest ascending subsequence

2.Elment Ui 日期选择器 格式化问题

Notes on C language learning of migrant workers majoring in electronic information engineering

Vgg16 migration learning source code

Octave instructions

Development of intelligent charging pile (I): overview of the overall design of the system

CV learning notes - reasoning and training

Opencv Harris corner detection

Dictionary tree prefix tree trie
随机推荐
Gpiof6, 7, 8 configuration
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
Octave instructions
(1) 什么是Lambda表达式
CV learning notes - deep learning
2021-01-03
Crash工具基本使用及实战分享
Connect Alibaba cloud servers in the form of key pairs
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
Stm32 NVIC interrupt priority management
My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
My notes on intelligent charging pile development (II): overview of system hardware circuit design
Replace the files under the folder with sed
STM32 running lantern experiment - library function version
LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
Opencv note 21 frequency domain filtering
LeetCode - 703 数据流中的第 K 大元素(设计 - 优先队列)
Emballage automatique et déballage compris? Quel est le principe?
About windows and layout
(2)接口中新增的方法