当前位置:网站首页>[force button] 35 Search insert location
[force button] 35 Search insert location
2022-06-28 16:24:00 【e1373773】
PHP Code :
do not know why , The force buckle cannot be submitted PHP The antithesis of , Is it just me ...
class Solution {
/**
* @param Integer[] $nums
* @param Integer $target
* @return Integer
*/
function searchInsert($nums, $target) {
$left = 0;
$right = count($nums) - 1;
if ($target > $nums[$right]) return count($nums);
if ($target < $nums[0]) return $left;
while ($left <= $right) {
$mid = intval($left + ($right - $left) / 2);
if ($target < $nums[$mid]) {
$right = ($mid) - 1;
} else if ($target > $nums[$mid]) {
$left = ($mid) + 1;
} else {
return $mid;
}
}
return $left;
}
}Their thinking ( Two points search ):
intval($left + ($right - $left) / 2);PHP The result of the division operation of may not be an integer , This needs attention .
Others can refer to the code itself .
边栏推荐
- Why MySQL table connection is faster than subquery
- QT interface library
- 扎克伯格致投资者:不要对元宇宙有任何期待
- Change exchange (dynamic planning)
- What you have to know under the digital collection boom
- 同创伟业合伙人童子平:“元宇宙”究竟该投什么
- 简单介绍一下tensorflow与pytorch的相互转换(主要是tensorflow转pytorch)
- LDD knowledge sorting
- Slim GAIN(SGAIN)介绍及代码实现——基于生成对抗网络的缺失数据填补
- Yesterday, yuancosmos | meta's "yuancosmos" Department lost $2.96 billion in the first quarter, and Liufu jewelry issued Digital Collections
猜你喜欢

A new 25K byte from the Department showed me what the ceiling is

岛屿类问题通用解法与DFS框架

Etcd可视化工具:Kstone简介(一)

Geoffrey Hinton:我的五十年深度学习生涯与研究心法

Focus on the 35 year old Kan: fear is because you don't have the ability to match your age

3. Caller 服务调用 - dapr

5 minutes to make a bouncing ball game

#夏日挑战赛#OHOS构建自定义服务实战

【初学者必看】vlc实现的rtsp服务器及转储H264文件

Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!
随机推荐
使用 Open Connector 进行 HubSpot 和 SAP 系统的集成工作
昨日元宇宙| 沃尔玛成立探索元宇宙和Web3的创新部门,Dior发布元宇宙展览
[recommendation system] esmm model of multi task learning (updating)
防火墙基础之流量管理与控制
How to query all the data in a table in the database?
3. caller service call - dapr
C#/VB.NET 将PDF转为Excel
面试官: 线程池是如何做到线程复用的?有了解过吗,说说看
5分钟的时间制作一个反弹球游戏
LDD knowledge sorting
Operating excel with openpyxl
A 24-year-old bald programmer teaches you how to continuously integrate and deliver microservice delivery. You can't learn how to cut me off
What you have to know under the digital collection boom
QT interface library
Introduction to reverse commissioning PE structure details 02/07
一台服务器最大并发 tcp 连接数多少?65535?
[Spock] process non ASCII characters in an identifier
General solution of island problems and DFS framework
超自动化与网络安全的未来
【Redis】2021/01/31 Redis的简单归纳 No.01