当前位置:网站首页>Binary search method
Binary search method
2022-07-03 10:35:00 【UniversalNature】
come from 704. Two points search
The framework is as follows :
// Version 2
class Solution {
public:
int search(vector<int>& nums, int target) {
int left = 0;
int right = nums.size(); // Definition target In the interval between left closed and right open , namely :[left, right)
while (left < right) {
// because left == right When , stay [left, right) It's invalid space , So use <
int middle = left + ((right - left) >> 1);
if (nums[middle] > target) {
right = middle; // target In the left range , stay [left, middle) in
} else if (nums[middle] < target) {
left = middle + 1; // target In the right range , stay [middle + 1, right) in
} else {
// nums[middle] == target
return middle; // Target value found in array , Return the subscript directly
}
}
// Target value not found
return -1;
}
};
边栏推荐
- 七、MySQL之数据定义语言(二)
- Ut2014 learning notes
- 20220606 Mathematics: fraction to decimal
- Powshell's set location: unable to find a solution to the problem of accepting actual parameters
- Leetcode刷题---977
- C#项目-寝室管理系统(1)
- Hands on deep learning pytorch version exercise solution - 2.6 probability
- A complete answer sheet recognition system
- R language classification
- 2018 y7000 upgrade hard disk + migrate and upgrade black apple
猜你喜欢

Ut2015 learning notes

ECMAScript--》 ES6语法规范 ## Day1

Ind wks first week

重写波士顿房价预测任务(使用飞桨paddlepaddle)

Standard library header file

Hands on deep learning pytorch version exercise solution - 3.1 linear regression

Secure in mysql8.0 under Windows_ file_ Priv is null solution

Model evaluation and selection

Introduction to deep learning linear algebra (pytorch)

Convolutional neural network (CNN) learning notes (own understanding + own code) - deep learning
随机推荐
Tensorflow—Image segmentation
The imitation of jd.com e-commerce project is coming
Policy Gradient Methods of Deep Reinforcement Learning (Part Two)
CSDN, I'm coming!
深度学习入门之线性代数(PyTorch)
神经网络入门之模型选择(PyTorch)
[LZY learning notes dive into deep learning] 3.5 image classification dataset fashion MNIST
Model evaluation and selection
侯捷——STL源码剖析 笔记
Ind FHL first week
A super cool background permission management system
20220609 other: most elements
八、MySQL之事务控制语言
Ut2014 learning notes
20220610 other: Task Scheduler
MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”解决方法
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
Neural Network Fundamentals (1)
Automatic derivation of introduction to deep learning (pytoch)
安装yolov3(Anaconda)