当前位置:网站首页>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;
}
};
边栏推荐
- Softmax 回归(PyTorch)
- 熵值法求权重
- Leetcode - 1172 plate stack (Design - list + small top pile + stack))
- Matrix calculation of Neural Network Introduction (pytoch)
- Drop out (pytoch)
- Pytorch ADDA code learning notes
- Leetcode - 5 longest palindrome substring
- Leetcode刷题---10
- Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
- Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition
猜你喜欢
A complete mall system
Policy Gradient Methods of Deep Reinforcement Learning (Part Two)
Model selection for neural network introduction (pytorch)
mysql5.7安装和配置教程(图文超详细版)
权重衰退(PyTorch)
Advantageous distinctive domain adaptation reading notes (detailed)
Policy gradient Method of Deep Reinforcement learning (Part One)
Softmax regression (pytorch)
Raspberry pie 4B deploys lnmp+tor and builds a website on dark web
ECMAScript--》 ES6语法规范 ## Day1
随机推荐
Timo background management system
Matrix calculation of Neural Network Introduction (pytoch)
Model evaluation and selection
Leetcode刷题---374
QT creator uses OpenCV Pro add
八、MySQL之事务控制语言
Hands on deep learning pytorch version exercise solution - 2.5 automatic differentiation
Leetcode skimming ---263
Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
ECMAScript--》 ES6语法规范 ## Day1
Ut2017 learning notes
Data preprocessing - Data Mining 1
20220607 others: sum of two integers
2018 Lenovo y7000 black apple external display scheme
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
LeetCode - 715. Range module (TreeSet)*****
Leetcode-106: construct a binary tree according to the sequence of middle and later traversal
六、MySQL之数据定义语言(一)
Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation
Leetcode - 5 longest palindrome substring