【Leetcode_easy】704. Binary Search
problem
solution:
class Solution {
public:
int search(vector<int>& nums, int target) {
int left = , right = nums.size()-, mid = ;
while(left<=right)//errr...
{
mid = left + (right-left)/;
if(nums[mid]<target) left = mid+;
else if(nums[mid]>target) right = mid-;
else return mid;
}
return -;
}
};
参考
1. Leetcode_easy_704. Binary Search;
完
【Leetcode_easy】704. Binary Search的更多相关文章
- 【LeetCode】704. Binary Search 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线性查找 二分查找 日期 题目地址:https:// ...
- 【LeetCode】Validate Binary Search Tree ——合法二叉树
[题目] Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defin ...
- 【LeetCode】二叉查找树 binary search tree(共14题)
链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given ...
- 【leetcode】Unique Binary Search Trees (#96)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 【leetcode】Validate Binary Search Tree
Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...
- 【leetcode】Unique Binary Search Trees
Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...
- 【leetcode】Recover Binary Search Tree
Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recove ...
- 【leetcode】Unique Binary Search Trees II
Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...
- 【leetcode】 Unique Binary Search Trees (middle)☆
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
随机推荐
- SCPI 语言简介
电子负载中需要用到,所以记录下.来源是德科技 SCPI(可编程仪器的标准命令)是一种基于 ASCII 的仪器编程语言,供测试和测量仪器使用. SCPI 命令采用分层结构,也称为树系统. 相关命令归组于 ...
- Z+F激光扫描仪
链接:https://zhuanlan.zhihu.com/p/48589754 三维扫描仪有三个误差来源: ● 线性误差(激光雷达部分/LARA) ● 测距噪声(激光雷达部分/LARA) ● 测角误 ...
- 发布一个在Web下输入密码时提示大写锁定键的Jquery插件
功能介绍:在Web下输入密码时提示大写锁定键,封装成jq插件方便有需要的同学!使用:$("#txtPWD").capsLockTip();截图预览:代码(2012-05-03 10 ...
- PHP爬虫之queryList
根据queryList 自己花了一个下午的时间写了一个爬星座数据的类,完全手写.附上代码 <?php require '../vendor/autoload.php'; use QL\Query ...
- 008——MATLAB-xlswrite的使用方法
(一)参考文献:https://blog.csdn.net/liangjiubujiu/article/details/80455753 以矩阵A=[1 2 3 4;5 6 7 8]为例进行介绍 例1 ...
- Vue中使用matomo进行访问流量统计的实现
Vue中使用matomo进行访问流量统计 原文链接 前言 之前做到了一个页面及接口访问流量统计的需求, 然后在网上找了很多帖子,发现有些有的但是写的都不是很详细,所以今天就整理了一下 正文 第一步 首 ...
- 洛谷 P1076 寻宝 题解
今天又TM考试了...... 这是T1,然后我模拟20分滚粗. Analysis 在每层的时候用编号%这层可以上楼的房间个数就行了. #include<iostream> #include ...
- 从零开始实现SSD目标检测(pytorch)(一)
目录 从零开始实现SSD目标检测(pytorch) 第一章 相关概念概述 1.1 检测框表示 1.2 交并比 第二章 基础网络 2.1 基础网络 2.2 附加网络 第三章 先验框设计 3.1 引言 3 ...
- C++标准库分析总结(二)——<模板,分配器,List>
本节主要总结模板及其类模板分类以及STL里面的分配器.容器内部结构以及容器之间的关系和分类,还介绍了容器中List的结构分布 1.源代码版本介绍 1.1 VC的编译器源码目录: 2.类模板 2.1 类 ...
- docker笔记--容器之间如何互相免密?
在使用docker搭建hadoop分布式集群的时候,需要各容器之间相互免密登录,传统的方式我想或许会很麻烦,特别是当容器达到几百上千台的时候,这时就需要有一种方式来更简单实现免密登录了. 环境介绍: ...