Lintcode14 First Position of Target Solution 题解
【题目描述】
For a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity.
If the target number does not exist in the array, return -1.
给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1。
【题目链接】
http://www.lintcode.com/en/problem/first-position-of-target/
【题目解析】
这题目要求O(logn)的复杂度,又是sorted array,话不多说我们来搞二分法。注意要求first position of target所以当(array[mid] == target)的时候,操作是end = mid。
二分查找到第一个target后使用逐个向前查询第一个target
全程使用二分查找
【答案链接】
http://www.jiuzhang.com/solutions/first-position-of-target/
转载于:https://blog.51cto.com/12799252/1919312
Lintcode14 First Position of Target Solution 题解相关推荐
- Lintcode61 Search for a Range solution 题解
[题目描述] Given a sorted array of n integers, find the starting and ending position of a given target v ...
- Lintcode132 Word Search || solution 题解
[题目描述] Given a matrix of lower alphabetsand a dictionary.Find all words in the dictionary that can b ...
- Lintcode18 Subsets II solution 题解
[题目描述] Given a list of numbers that may has duplicate numbers, return all possible subsets Notice:Ea ...
- Lintcode42 Maximum Subarray II solution 题解
[题目描述] Given an array of integers, find two non-overlapping subarrays which have the largest sum.The ...
- Lintcode108 Palindrome Partitioning || solution 题解
[题目描述] Given a strings, cutsinto some substrings such that every substring is a palindrome. Return t ...
- Lintcode363 Trapping Rain Water solution 题解
[题目描述] Given n non-negative integers representing an elevation map where the width of each bar is 1, ...
- Lintcode107 Word Break solution 题解
[题目描述] Given a string s and a dictionary of words dict, determine if s can be break into a space-sep ...
- Lintcode189 First Missing Positive solution 题解
[题目描述] Given an unsorted integer array, find the first missing positive integer. 给出一个无序的整数数组,找出其中没有出 ...
- Lintcode99 Reorder List solution 题解
[题目描述] Given a singly linked list L: L0→ L1→ - → Ln-1→ Ln reorder it to: L0→ Ln→ L1→ Ln-1→ L2→ Ln-2→ ...
最新文章
- 朋友在小厂待到三十多岁了 现在跳槽能找到什么样的工作
- Yahoo!的网站项目工作流程
- 配置lamp+supervisor
- python numpy.random模块中提供啦大量的随机数相关的函数
- poj 2976 基础01分数规划
- AndroidStudio 3.4更新了啥?(转载)
- 程序员求职面试丨面试必备之终极指导篇,掌握这些,面试不再困难!
- CoreOS rpm-ostree简介
- 报告正在使用哪些Reporting Services数据集字段?
- 把斯坦福大学土地租出去?特曼坦言:目的就是赚钱
- 【李宏毅2020 ML/DL】P35-42 Attack ML Models
- android md5使用方法,android 使用DigestUtilsmd5加密的方法
- udp程序启动后检测都是未启动_【例子教程】联想Leez P710 物联网AI物体检测
- VMware下Ubuntu 18.04关机后无法上网
- Http协议规范及格式
- 混合分布(mixture distribution)
- 全国30m精度土壤类型分布矢量数据、土壤理化性质数据集
- Cortex-M3 (NXP LPC1788)之GPIO
- 敏捷开发快速入门(四):Scrum开发流程
- 栈——后进先出的增删改查
热门文章
- java微信上传图片_微信小程序图片上传java后台(前后端代码)
- python获取月份字符串_python - python从字符串获取日期 - 堆栈内存溢出
- python相册特效模块_PIL包中Image模块的convert()函数的具体使用
- springboot+mybatis+shiro+beetl前端做 服务监控页面
- android xml反编译原理,记一次resources.arsc文件hex修改原理分析
- java自定义findbugs规则,定制 findbugs规则 - 阿里巴巴一个测试架构师 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...
- 期末C语言45分能过的吗,C语言—期末小黄衫获奖感言
- 机器人改变生活利弊英语作文_左手建筑右手餐饮,机器人如何改变大众生活? 圆梦人感言...
- CSS去掉TextBox边框
- jsp中提供的四种属性范围