当前位置:网站首页>【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
边栏推荐
- Jin AI her power | impact tech, she can
- 2022-02-28 incluxdb high availability planning
- Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
- leetcodeSQL:574. Elected
- C语言:如何给全局变量起一个别名?
- Flutter series part: detailed explanation of GridView layout commonly used in flutter
- 管线中的坐标变换
- Hostvars in ansible
- 大学期间零基础如何开展编程学习
- Ansible summary (VI)
猜你喜欢

JVM Basics - > What are the thread shared areas in the JVM

Preliminary use of jvisualvm

A puzzle about + =

How to prevent phishing emails? S/mime certificate to help!

Su embedded training day13 - file IO

MySQL introduction and installation (I)

Use group_ Dplyr issues when using group_ by(multiple variables)

Audio and video technology development weekly 𞓜 234

(downloadable) Research Report on the development and utilization of government data (2021), a glimpse of the development of Government Office
![[probability theory and mathematical statistics] final review: formula summary and simple examples (end)](/img/f5/1c8392aaf87ea323524e94e3f213ed.png)
[probability theory and mathematical statistics] final review: formula summary and simple examples (end)
随机推荐
China's elastic belt market trend report, technical dynamic innovation and market forecast
Design a MySQL table for message queue to store message data
JVM foundation - > What garbage collectors does the JVM have?
JVM Basics - > What are the JVM parameters?
Wechat applet withdrawal function
List of open source alternative projects of world famous Cloud Service SaaS companies
June training (day 11) - matrix
Qt Quick 3D学习:使用鼠标键盘控制节点位置和方向
Why is pain rating important?
Ansible roles project case (IV)
JVM foundation - > three ⾊ mark
LNMP platform docking redis service
be careful! Your Navicat may have been poisoned
证券开户有风险吗?怎么开户安全呢?
C#读取word中表格数据
MySQL introduction and installation (I)
[simple] 155 Minimum stack
MySQL architecture and basic management (II)
【Web技术】1348- 聊聊水印实现的几种方式
ShardingSphere-proxy-5.0.0部署之分表实现(一)