Given a sorted array of integers, find the starting and ending position of a given target value.

Your algorithm's runtime complexity must be in the order of O(log n).

If the target is not found in the array, return [-1, -1].

For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, 4].

class Solution {
public:
vector<int> searchRange(int A[], int n, int target) {
set<int> sIndex;
search(A,,n-,target,sIndex);
vector<int> result(,-);
if(!sIndex.empty()){
result[] = *sIndex.begin();
result[] = *(--sIndex.end());
}
return result; }
private:
void search(int A[],int start,int end,int target,set<int> &sIndex){ if(start == end){
if(A[start]==target){
sIndex.insert(start);
return;
}else
return;
} int startIndex,endIndex;
int mid = start + (end-start)/; if(A[start]<=target && A[mid]>= target)
search(A,start,mid,target,sIndex);
if(A[mid+]<=target && A[end]>= target)
search(A,mid+,end,target,sIndex);
}//end func
};

[LeetCode] Search for a Range(二分法)的更多相关文章

  1. leetcode 34 Search for a Range(二分法)

    Search for a Range Given a sorted array of integers, find the starting and ending position of a give ...

  2. LeetCode: Search for a Range 解题报告

    Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given ...

  3. [LeetCode] Search for a Range 搜索一个范围

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  4. leetcode Search for a Range python

    class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int ...

  5. [LeetCode] Search for a Range 二分搜索

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  6. Leetcode Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  7. leetcode:Search for a Range(数组,二分查找)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  8. leetcode -- Search for a Range (TODO)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  9. [LeetCode] Search for a Range [34]

    题目 Given a sorted array of integers, find the starting and ending position of a given target value. ...

随机推荐

  1. hadoop2.2.0部署

    hadoop2.2.0部署 下载安装包 hadoop-2.2.0-cdh5.0.0-beta-1.tar.gz 解压 tar zxvf hadoop-2.2.0-cdh5.0.0-beta-1.tar ...

  2. python 代码片段10

    #coding=utf-8 #元组是列表的近亲.列表用方括号,元组用小括号 #django配置文件大量用到元组 #注意,单个元素的元组要求在最后"必须"跟一个逗号. a=(&quo ...

  3. unity button

    #pragma strict var buttonTexture:Texture2D; private var str:String; private var frameTime:int; funct ...

  4. 【wikioi】1403 新三国争霸(dp+kruskal)

    http://wikioi.com/problem/1403/ 一开始的确感觉和bzoj1003很像,不同的是这里还要求联通,求最小的边. 我们可以想到用最小生成树(为嘛我自己想不到呢..) 我们可以 ...

  5. Graph database_neo4j 底层存储结构分析(6)

    3.6  Node 数据存储 neo4j 中, Node 的存储是由 NodeStore 和 ArrayPropertyStore 2中类型配合来完成的. node 的label 内容是存在Array ...

  6. jQuery.Validate验证库详解

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

  7. #undef

    #undef 是在后面取消以前定义的宏定义 该指令的形式为 #undef 标识符 其中,标识符是一个宏名称.如果标识符当前没有被定义成一个宏名称,那么就会忽略该指令. 一旦定义预处理器标识符,它将保持 ...

  8. fastjson解析任意json

    fastjson解析任意json到bean 解析案例的代码 package com.base.config; import java.util.List; import com.alibaba.fas ...

  9. HDU 1394 Minimum Inversion Number(线段树/树状数组求逆序数)

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  10. html5_d登陆界面_注册界面

    <!DOCTYPE html><html><head><script type="text/javascript">function ...