当前位置:网站首页>Sword finger offer 53 - I. find the number I in the sorted array
Sword finger offer 53 - I. find the number I in the sorted array
2022-07-05 05:28:00 【ThE wAlkIng D】
Title Description

)
Problem analysis
The two methods
The first one is : Violent settlement .
The second kind : Use bisection search , Because it is a sorted array , For the value found , Let him judge whether it is equal , If equal, let count+1;
Code instance
class Solution {
public int search(int[] nums, int target) {
int lefet = 0,right = nums.length()-1,count = 0;
while(left < right){
int mid = (left + right)/2;
if(nums[mid] >= target){
right = middle - 1;
}
if(nums[mid] < target){
left = middle + 1;
}
}
while(left < nums.length&&nums[left++] == target){
count++;
}
return count;
}
}
边栏推荐
猜你喜欢

Service fusing hystrix
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

On-off and on-off of quality system construction
![[turn]: OSGi specification in simple terms](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[turn]: OSGi specification in simple terms

剑指 Offer 53 - II. 0~n-1中缺失的数字

lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8

远程升级怕截胡?详解FOTA安全升级
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
[merge array] 88 merge two ordered arrays
![[转]MySQL操作实战(三):表联结](/img/70/20bf9b379ce58761bae9955982a158.png)
[转]MySQL操作实战(三):表联结

读者写者模型
随机推荐
注解与反射
MySQL数据库(一)
National teacher qualification examination in the first half of 2022
Maximum number of "balloons"
[to be continued] [UE4 notes] L1 create and configure items
How can the Solon framework easily obtain the response time of each request?
Mysql database (I)
Under the national teacher qualification certificate in the first half of 2022
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
Web APIs DOM节点
On-off and on-off of quality system construction
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
High precision subtraction
Little known skills of Task Manager
剑指 Offer 09. 用两个栈实现队列
[allocation problem] 135 Distribute candy
Reader writer model
Yolov5 ajouter un mécanisme d'attention
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization