当前位置:网站首页>Sword finger offer 53 - ii Missing numbers from 0 to n-1
Sword finger offer 53 - ii Missing numbers from 0 to n-1
2022-07-18 21:09:00 【anieoo】
Original link : The finger of the sword Offer 53 - II. 0~n-1 Missing numbers in
solution:
Two points , An ordered array can be divided into two parts , The first part is the array value corresponding to the subscript , The second part is that the subscript and array values are not equal , Use bisection to find the position where the first subscript is not equal to the array value .
class Solution {
public:
int missingNumber(vector<int>& nums) {
int l = 0,r = nums.size();
while(l < r) {
int mid = (l + r) >> 1;
if(nums[mid] != mid) r = mid;
else l = mid + 1;
}
return l;
}
};边栏推荐
- stm32F407----电源管理
- Scrcpy projection
- R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用step函数基于AIC指标实现逐步回归筛选最佳模型
- Apache log related
- docker mysql
- 数学方法 - 封装范围内随机整数-六位随机验证码-随机颜色字符串-进制转换 和 保留小数位
- Offre de doigts 57. Et deux chiffres pour s
- Programming implementation of I2C communication protocol
- Epic-kbs9 industrial computer brushing document
- R语言ggplot2可视化:ggplot2可视化密度图(density plot)并使用geom_vline函数添加均值竖线、添加均值数值标签(Mean Line or Vertical Line )
猜你喜欢

Uniapp request request encapsulation method

Pending issues

Find out the motivation and needs of enterprise location, and carry out investment attraction work efficiently

剑指 Offer 57. 和为s的两个数字

浅谈数组方法重构再封装-forEach-Map——push(),unshift(),shift(),Map(),filter(),every(),some(), reduce()

Redis - 槽管理命令详解

prettier代码格式化工具的使用

基于STM32电源模块开发

这个加热器的热特性

每日刷题记录 (二十五)
随机推荐
R language uses LM function to build multiple regression model, writes regression equation according to model coefficient, and uses summary function to calculate the summary statistical information of
Redis - 槽管理命令详解
R language uses pcauchy function to generate Cauchy distribution cumulative distribution function data, and uses plot function to visualize Cauchy distribution cumulative distribution function data
I2C通信协议实现在OLED显示屏数据显示
Pytorch 深度可分离卷积和MobileNet_v1
VirtualBox virtual machine failed to start, e_ FAIL( 0x80004005)
Apache log related
World Tour Finals 2019 D - Distinct Boxes 题解
每日刷题记录 (二十五)
docker mysql
Markdown basic syntax format
Sword finger offer 55 - I. depth of binary tree
基于 Servlet 项目——博客系统
Development of power module based on stm32
Electron installation configuration
[亲测有效]npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
高级程序员面试常用问题,你知道回答吗? 带答案
R language uses the range function of dplyr package to sort dataframe, and the range function performs descending sorting based on a field (variable)
关于#sql#的问题:orcale sql, 为什么MERCHANT table的外键inventory—id 语句是无效的
R language ggplot2 visualization: use the gghistogram function of ggpubr package to visualize the histogram, use the add parameter to add the mean dotted line, vertical line and horizontal axis to the