当前位置:网站首页>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;
}
}
边栏推荐
- 搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
- [trans]: spécification osgi
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- [es practice] use the native realm security mode on es
- Haut OJ 1243: simple mathematical problems
- [merge array] 88 merge two ordered arrays
- [转]MySQL操作实战(三):表联结
- Improvement of pointnet++
- Acwing 4301. Truncated sequence
- 挂起等待锁 vs 自旋锁(两者的使用场合)
猜你喜欢
随机推荐
ALU逻辑运算单元
Yolov5 ajouter un mécanisme d'attention
YOLOv5添加注意力机制
Control Unit 控制部件
[depth first search] 695 Maximum area of the island
Csp-j-2020-excellent split multiple solutions
[turn to] MySQL operation practice (I): Keywords & functions
剑指 Offer 58 - II. 左旋转字符串
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
[转]: OSGI规范 深入浅出
Time complexity and space complexity
Pointnet++ learning
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
剑指 Offer 05. 替换空格
[to be continued] [UE4 notes] L2 interface introduction
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
Under the national teacher qualification certificate in the first half of 2022
A preliminary study of sdei - see the essence through transactions
[interval problem] 435 Non overlapping interval









