【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 ...
随机推荐
- 1~n中数字0~9出现的次数
题意:rt 分析: 当然不可能去遍历,应该寻找统计的方法. 如计算 78501 中 "5" 出现的次数. 我们可以枚举“5”出现的位置, 如当“5”位于倒数第2位时,写成 xxx5 ...
- 去除IDEA中xml黄色背景
idea版本:IntelliJ IDEA 2019.2.1 在编写mybatis的xml中会出现大面积黄色背景提示,看起来比较不舒服. 去掉黄色背景颜色 1.打开File->Settings-& ...
- js图片上传 的方法
先规划出框架 <div id="AQA" style="width:300px; height:200px; background-color:aquamarine ...
- 轻松掌握mongodb
mongodb 是一种非关系型的,面向文档的数据库,也是nosql类的产品 memcache,redis等等 与mysql最大的区别:mongodb 使用javascript语言操作,保存是以json ...
- 洛谷 P2119 魔法阵 题解
Analysis 这道题也是考试题,我也依然打了个n三次方暴力.正解是先枚举差,再枚举c和d,a和b用乘法原理优化,这样就能大大减少时间. #include<iostream> #incl ...
- Python获取百度浏览记录
Python模拟百度登录实例详解 http://www.jb51.net/article/78406.htm Python实战计划学习作业2-1 http://blog.csdn.net/python ...
- Linux操作系统常用命令合集——第二篇- 用户和组操作(15个命令)
一.前言:本篇介绍用户和组操作的15个命令,在介绍之前我们先来看看几个示例 1.先进入到etc目录下,找到passwd文件,用vi编辑器查看: # vi /etc/passwd 解释:这里面存放着Li ...
- DOM操作1
1.DOM文档对象模型:操作页面元素(标签) html文件看成一个文档,把文档看成一个对象 xml也是一种文档,标签自定义,系统不自带标签,偏向于存储数据 2.DOM树:由文档及文档中的所以元素(标签 ...
- 当margin和padding的值是百分比时,如何计算
对元素的margin设置百分数时,百分数是相对于自身包含块的width计算(包含块传送门),不管是margin-top/margin-bottom还是margin-left/margin-right. ...
- 炸掉的fft,改天再调
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> ...