当前位置:网站首页>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;
}
}
边栏推荐
- 剑指 Offer 53 - II. 0~n-1中缺失的数字
- A new micro ORM open source framework
- To the distance we have been looking for -- film review of "flying house journey"
- [allocation problem] 455 Distribute cookies
- 使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
- Pointnet++ learning
- Reader writer model
- Drawing dynamic 3D circle with pure C language
- Reverse one-way linked list of interview questions
- Little known skills of Task Manager
猜你喜欢
[turn]: OSGi specification in simple terms
Little known skills of Task Manager
读者写者模型
National teacher qualification examination in the first half of 2022
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
[to be continued] [UE4 notes] L3 import resources and project migration
C language Essay 1
剑指 Offer 05. 替换空格
Pointnet++ learning
[to be continued] [UE4 notes] L1 create and configure items
随机推荐
SSH password free login settings and use scripts to SSH login and execute instructions
Programmers' experience of delivering takeout
Solon Auth 认证框架使用演示(更简单的认证框架)
Haut OJ 1241: League activities of class XXX
Use of room database
2022上半年全国教师资格证下
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
Pointnet++的改进
服务熔断 Hystrix
剑指 Offer 06.从头到尾打印链表
A misunderstanding about the console window
剑指 Offer 05. 替换空格
Improvement of pointnet++
Service fusing hystrix
Acwing 4300. Two operations
Reader writer model
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
[to be continued] [UE4 notes] L2 interface introduction
Binary search basis
YOLOv5-Shufflenetv2