当前位置:网站首页>【LeetCode】69. Square root of X
【LeetCode】69. Square root of X
2022-06-12 22:21:00 【LawsonAbs】
1. subject
Do not use system built-in functions , Please give the square root of a number .
2. thought
Use dichotomy .
- Pay attention to the treatment of special values 【 I flipped the car here twice 】
3. Code
class Solution:
def mySqrt(self, x: int) -> int:
low,high=0,x
# Find a suitable subscript , Even if they are equal , Also continue to find
while(low <= high):
mid=(low+high) //2
# print(low,high,mid)
if x == mid * mid:
return mid
if mid == 0: # If mid = 0, So it must be low=0,high = 1
low = mid+1
continue
if x // mid >= mid: # If
low = mid + 1
else:
high = mid - 1
# end while when , low > high
# Finally, let's judge
return high
边栏推荐
- NoSQL - redis configuration and optimization (II) high availability, persistence and performance management
- What is embedded
- 孙老师版本JDBC(2022年6月12日21:34:25)
- China barcode decoder market trend report, technical innovation and market forecast
- Create a virtual thread using loom - David
- "Oracle database parallel execution" technical white paper reading notes
- Research Report on truffle fungus industry - market status analysis and development prospect forecast
- vim利用右下4键
- QT quick 3D learning: use mouse and keyboard to control node position and direction
- Mysql concat_ws、concat函数使用
猜你喜欢
![[image denoising] image denoising based on trilateral filter with matlab code](/img/f2/770a0e2938728e731c18c0a66f7c12.png)
[image denoising] image denoising based on trilateral filter with matlab code

PE installation win10 system

RAID disk array

JVM foundation - > three ⾊ mark

Qt Quick 3D学习:鼠标拾取物体

Redis optimization

Photoshop:PS如何实现放大图片不模糊

Ansible PlayBook et ansible roles (3)

Ansible基础和常用模块(一)

Configuring Dingding notification of SQL audit platform archery
随机推荐
June training (day 11) - matrix
Pat grade A - 1167 Cartesian tree (30 points) (buildtree + level traversal)
Unity commonly used 3D mathematical calculation
The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
经济学人聚焦WTO MC12:数字经济或成重要议题
打新债开户安全么,新手该怎么操作?
認識的幾比特清華同學都離職了……
设计消息队列存储消息数据的 MySQL 表格
China barcode decoder market trend report, technical innovation and market forecast
【图像去噪】基于三边滤波器实现图像去噪附matlab代码
China's elastic belt market trend report, technical dynamic innovation and market forecast
What is the difference between volatile variables and atomic variables?
42岁大厂高管,给30岁-39岁人提个醒:这6个让你变强的习惯,要尽快养成
[sword finger offer] sword finger offer 35 Replication of complex linked list
[C language] data type occupation
Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
项目里面的traceID的设计
C#读取word中表格数据
最近公共祖先问题你真的学会了吗?
ShardingSphere-proxy-5.0.0部署之分表实现(一)