problem

704. Binary Search

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的更多相关文章

  1. 【LeetCode】704. Binary Search 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线性查找 二分查找 日期 题目地址:https:// ...

  2. 【LeetCode】Validate Binary Search Tree ——合法二叉树

    [题目] Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defin ...

  3. 【LeetCode】二叉查找树 binary search tree(共14题)

    链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given ...

  4. 【leetcode】Unique Binary Search Trees (#96)

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  5. 【leetcode】Validate Binary Search Tree

    Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...

  6. 【leetcode】Unique Binary Search Trees

    Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...

  7. 【leetcode】Recover Binary Search Tree

    Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recove ...

  8. 【leetcode】Unique Binary Search Trees II

    Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) ...

  9. 【leetcode】 Unique Binary Search Trees (middle)☆

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

随机推荐

  1. 实现strStr()函数

    方法一:暴力解法 int strStr(string haystack, string needle) { if (needle.empty()) ; int M = haystack.size(); ...

  2. HTML 008 head

    HTML <head> 查看在线实例 <title> - 定义了HTML文档的标题使用 <title> 标签定义HTML文档的标题 <base> - 定 ...

  3. CSPS模拟88-91

    感觉自己好菜啊,考得一次不如一次了...压力好大,++滚粗感. 模拟88. T1,sbt,发现离散化后数据范围变为6000,直接跑暴力即可.%%%机房众神斜率优化. T2,大模拟,考场上只会乱搞骗分. ...

  4. Luogu4688 [Ynoi2016]掉进兔子洞 【莫队,bitset】

    题目链接:洛谷 我们知道要求的是\([l_1,r_1],[l_2,r_2],[l_3,r_3]\)的可重集取交的大小,肯定是要用bitset的,那怎么做可重集呢? 那就是要稍微动点手脚,首先在离散化的 ...

  5. [bzoj 1861][zjoi2006] 书架

    传送门 Description 1. Top S--表示把编号为S的书放在最上面. 2. Bottom S--表示把编号为S的书放在最下面. 3. Insert S T--T∈{-1,0,1},若编号 ...

  6. hadoop--presto安装部署

    系统环境:hadoop + hive已经配置完成 1.下载presto:https://repo1.maven.org/maven2/com/facebook/presto/presto-server ...

  7. [APIO2017]商旅——分数优化+floyd+SPFA判负环+二分答案

    题目链接: [APIO2017]商旅 枚举任意两个点$(s,t)$,求出在$s$买入一个物品并在$t$卖出的最大收益. 新建一条从$s$到$t$的边,边权为最大收益,长度为原图从$s$到$t$的最短路 ...

  8. radio回显的

    JS回显 var jksp=document.getElementsByName("spjdcyModel.jksp"); // alert(jksp[0].value); //a ...

  9. netcore 发布到IIS上常见错误

    1 出现AspNetCoreModuleV2错误 报错原因: 你的IIS服务器上的.net core 运行时不是最新的,导致AspNetCoreModuleV2模块缺失或者报错,意思需要你更新了! 2 ...

  10. Radix Heap ---Dijkstra算法的优化 BY Gremount

    Radix Heap 算法是在Dijkstra的Dial实现的基础上,通过减少对桶的使用,来优化算法的时间复杂度: Dial 时间复杂度是O(m+nC)     -------C是最长的链路 Radi ...