博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 34. Search for a Range
阅读量:4662 次
发布时间:2019-06-09

本文共 643 字,大约阅读时间需要 2 分钟。

问题描述:

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].

解释:

  给一串数组,在其中找出某一个数第一次出现和最后一次出现的位置,放在一个数组返回,没找到就返回[-1,-1];如给定数组[5, 7, 7, 8, 8, 10]和数字8,结果就是[3,4]

程序(用js写的):

1 /** 2  * @param {number[]} nums 3  * @param {number} target 4  * @return {number[]} 5  */ 6 var searchRange = function(nums, target) { 7     var res=[]; 8     for(var i=0;i

 

转载于:https://www.cnblogs.com/hongrunhui/p/5189745.html

你可能感兴趣的文章
Tomcat创建HTTPS访问,java访问https
查看>>
Matlab实现IIR数字滤波器设计
查看>>
java常见异常
查看>>
手动添加PopMenu出现的问题
查看>>
Linux 远程桌面 访问 WIndows
查看>>
SQLServer存储过程自制数据字典
查看>>
TCP的粘包问题
查看>>
树上有十只鸟,开枪打死一只,还剩几只?
查看>>
随机生成汉字(摘录保存的代码)
查看>>
敢于面对惨淡的人生
查看>>
【bzoj 1119】 [POI2009] SLO(置换群)
查看>>
leetcode[19]Remove Nth Node From End of List
查看>>
Spring 系列: Spring 框架简介
查看>>
DataTable转换成IList
查看>>
web开发的模式
查看>>
【深入ASP.NET原理系列】--Asp.Net Mvc和Asp.Net WebForm实际上共用一套ASP.NET请求管道...
查看>>
Windows下搭建PHP开发环境(Apache+PHP+MySQL)
查看>>
做产品原型设计有哪些需要注意的问题——吐槽下目前产品需求原型一直以来被前端诟病的地方...
查看>>
mysql 中的存储过程
查看>>
IP协议详解
查看>>