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. django安装tinymce

    1. pip install django-tinymce 2. 运行:python manage.py collectstatic 3. 编辑 settings.py 4. TINYMCE_JS_U ...

  2. Elasticsearch 监控

    导语 Elasticsearch(文中简称ES)是分布式全文搜索引擎,产品提供高可用.易扩展以及近实时的搜索能力,广泛应用于数据存储.搜索和实时分析.很多服务的可用性对ES重度依赖.因此,保障ES自身 ...

  3. openssl制作双向认证经过验证可行

    openssl制作双向认证经过验证可行 http://www.360doc.com/content/12/0524/15/2150778_213390447.shtml 2012-05-24  履历馆 ...

  4. PHP的输出语法

    一.echo 只能输出标量数据类型,对于任何数据都可以转为字符串输出 echo是PHP的一种特殊的'指令',不一定要像函数的那样()去使用,可以直接紧跟一个空格输出信息,可以是多个参数 <?ph ...

  5. 三个方法(apply、call、bind)

    一.apply()和call() 方法中如果没传入参数,或者是null,那么调用该方法的函数对象中的this就是默认的window <script> function f1(x,y){ c ...

  6. hdu 3 * problem

    hdu 6182 给出 $n$ 求 $\sum_{i = 1} ^ {\infty} (i * i <= n)$ 暴力枚举 hdu 6186 给出 $n$ 个数 $1e6$ 次询问,每次询问这 ...

  7. P1929 迷之阶梯

    题目描述 在经过地球防卫小队的数学家连续多日的工作后,外星人发的密码终于得以破解.它 告诉我们在地球某一处的古老遗迹中,存在有对抗这次灾难的秘密武器.防卫小队立即赶 到这处遗迹.要进入遗迹,需要通过一 ...

  8. Java基础系列 - 接口(功能,用途和优势)

    package com.test1; /** * 接口的使用 */ public class test1 { public static void main(String[] args) { //创建 ...

  9. NOIP2014提高组 题解报告

    D1 T1 无线网路发射器选址 题目大意:找一个矩形,使其覆盖的目标点最大. 题目过水,直接暴力搞过去,代码就不贴了. 但我TM居然有个地方SB了,调了半天才发现输入有问题: scanf(" ...

  10. 深入理解JVM虚拟机1:JVM内存的结构与永久代的消失

    所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...