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. 什么是OAuth

    什么是OAuth 如今很多网站的功能都强调彼此间的交互,因此我们需要一种简单,标准的解决方案来安全的完成应用的授权,于是,OAuth应运而生,看看官网对其的定义: An open protocol t ...

  2. ORACLE 表连接详解

    在ORACLE中,表连接方式主要有:内连接,外连接,自连接: 内连接: 这是最常用的连接查询 SELECT * FROM A INNER JOIN B ON A.ID=B.ID SELECT * FR ...

  3. 代码混淆 GSON完满解决

    头疼的问题,json使用了google的gson三方包,可是混淆的时候出了问题 明明已经按照gson的官方文档,把混淆脚本加上去了,却还是出问题. 今天同事找到一篇博客,关于这个问题的: 我们是将js ...

  4. Android appcompat备案

    使用Eclipse创建Android项目,project多出appcompat_v7,此情况在ADT升级到22.6.x版本后出现,22.3.x前版本不存在.此项为了实现向下兼容sdk的功能. 点击项目 ...

  5. 【贪心】【TOJ4107】【A simple problem】

    Given three integers n(1≤n≤1018), m(1≤m≤105), k(1≤k≤1018). you should find a list of integer A1,A2,- ...

  6. IOS支付宝支付出现6002问题的解决办法

    运行支付宝官方demo进行支付测试,会出现6002-网络连接错误,是因为以iOS9 SDK编译的工程会默认以SSL安全协议进行网络传输,即HTTPS,如果依然使用HTTP协议请求网络会报系统异常并中断 ...

  7. [Linked List]Rotate List

    Total Accepted: 55428 Total Submissions: 250727 Difficulty: Medium Given a list, rotate the list to ...

  8. mysql的高级用法

    1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...

  9. MySql的like语句中的通配符:百分号、下划线和escape 的使用

    MySql的like语句中的通配符:百分号.下划线和escape %代表任意多个字符 select * from user where username like '%huxiao'; select ...

  10. 解析处理常用json数据总结

    工作中用ajax接收到接口返回的数据需要进行解析后操作,这里总结一下平时的方法,用的jquery,复制下来的页面把引入的路径改一下即可. <!DOCTYPE html> <html ...