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. 去除express.js 3.5中报connect.multipart() will be removed in connect 3.0的警告

     1 $ node app.js  2 connect.multipart() will be removed in connect 3.0  3 visit https://github.com/s ...

  2. magento新闻邮件发送一直处于“正在发送”状态问题解决

    今天在弄magento新闻邮件发送时候发现,单个邮件发送全然没有问题,可是新闻邮件订阅死活都不成功.国内国外的帖子都翻了一遍没实用,最后还是得靠自己了.于是開始慢慢找问题 首先想到是不是crontab ...

  3. js简易写法

    我写JavaScript代码已经很久了,都记不起是什么年代开始的了.对于JavaScript这种语言近几年所取得的成就,我感到非常的兴奋:我很幸运也是这些成就的获益者.我写了不少的文章,章节,还有一本 ...

  4. IIS出现Server Application Unavailable的解决办法

    在XP中IIS5.1服务器,运行asp.net出现Server Application Unavailable,经过多次查证,才发现是因为先安装了.net Framework 2.0然后安装IIS,导 ...

  5. php基础_2

    php可变变量: $a = "hello"; $$a = "world"; echo $a . $$a; 输出:hello world; current — 返 ...

  6. Qt5 多显示器获取不同显示器的分辨率和位置的方法

    Qt5 多显示器获取不同显示器的分辨率和位置的方法 先放官方文档链接:QDesktopWidget - Qt5 Reference 之前一直在用被我乱搞后的ShadowPlayer作为默认播放器,后来 ...

  7. 音量强度转分贝db

    //LPDIRECTSOUNDBUFFER如何设置声音大小?> //取值范围是0 ~ -10000, 0最大,-10000最小,单位是分贝 //0-100音量转换成分贝 double decib ...

  8. MySQL安全问题

    使用MySQL,安全问题不能不注意.以下是MySQL提示的23个注意事项:1.如果客户端和服务器端的连接需要跨越并通过不可信任的网络,那么就需要使用SSH隧道来加密该连接的通信.2.用set pass ...

  9. Ubuntu 12.04 wireless networks : devices not ready (firmware missing)解决办法

    今天装了Ubuntu12.04之后,发现无线不能用. 用iwconfig查看,wlan0 项后面有内容,但是在本该显示无线列表的地方显示的是 “ wireless networks : devices ...

  10. js问题学习

    1.前言为了node.js做准备,js的基本功还是很重要的.所以正值1024程序员节的时候所以找了些题目,整理了一下知识点.这篇文章感觉代码太多,难免枯燥,所以文章最后留了个彩蛋给读者. 2.简单回调 ...