class Solution(object):
def searchRange(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
""" left=0
right=len(nums)-1 while left <= right:
mid=(left+right)/2
if nums[mid] > target:
right=mid-1
elif nums[mid] < target:
left=mid+1
else:
rs=[0,0]
if nums[left] == target:
rs[0] = left
if nums[right] == target:
rs[1] = right
for i in range(mid,right+1):
if nums[i] != target:
rs[1] = i-1
break
for i in range(mid,left-1,-1):
if nums[i] != target:
rs[0] = i + 1
break
return rs
return [-1,-1]

leetcode Search for a Range python的更多相关文章

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

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

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

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

  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(数组,二分查找)

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

  5. [leetcode]Search a 2D Matrix @ Python

    原题地址:https://oj.leetcode.com/problems/search-a-2d-matrix/ 题意: Write an efficient algorithm that sear ...

  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. OAuth2.0认证介绍

    OAuth2.0鉴权 返回 目录 [隐藏] 1 腾讯微博OAuth2.0认证介绍 2 获取accesstoken的两种方式 2.1 1.Authorization code grant 2.1.1 第 ...

  2. Objective-C——判断对象等同性

    无论我们使用什么语言,总是会出现需要判断两个对象是否相等的情况,OC当然也不例外.首先看一段代码: NSString *str1 = [[NSString alloc] initWithCString ...

  3. HTML5添加背景音乐

    html5 audio 给博客 网页加背景音乐 可以加上个按钮或者链接 让其可停止或暂停 下面代码只是暂停 可以弄成暂停 播放两种状态切换.. 可以考虑换成a标签 <a href="# ...

  4. JavaScript学习笔记——简单无缝循环滚动展示图片的实现

    今天做了一个简单的无缝循环滚动的实例,这种实例在网页中其实还挺常见的,下面分享一下我的学习收获. 首先,无缝滚动的第一个重点就是——动.关于怎么让页面的元素节点动起来,这就得学明白关于JavaScri ...

  5. DEV GridControl导出到Excel或打印

    //方法1SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Title = "导出Excel"; fileD ...

  6. 反编译C#的dll文件并修改,再重新生成dll

    1.把dll文件导入到ildasm工具中,ildasm是由微软提供的.net程序反编译工具,位于“C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A ...

  7. 初学DIV+CSS要记住的

    初学DIV+CSS?有六个问题需要您关注一下!作为DIV+CSS初学者,如果在动手写代码之前对网页整体结构由一个清晰认识的话,写起来会事半功倍!但是,写的过程中总是有这样那样的问题,使得我们不得不停下 ...

  8. n条直线的最多交点

    #include <iostream>using namespace std;int main(){int i,n;while(cin>>n){if(n==0||n==1) c ...

  9. 贝叶斯网络基础(Probabilistic Graphical Models)

    本篇博客是Daphne Koller课程Probabilistic Graphical Models(PGM)的学习笔记. 概率图模型是一类用图形模式表达基于概率相关关系的模型的总称.概率图模型共分为 ...

  10. Android 弹出窗体

    findViewById(R.id.btn).setOnClickListener(new OnClickListener() { @Override public void onClick(View ...