当前位置:网站首页>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;
}
}
边栏推荐
- [to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
- Control Unit 控制部件
- 注解与反射
- A preliminary study of sdei - see the essence through transactions
- Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
- 游戏商城毕业设计
- FVP和Juno平台的Memory Layout介绍
- Pointnet++的改进
- Talking about JVM (frequent interview)
- [to be continued] [UE4 notes] L1 create and configure items
猜你喜欢
随机推荐
Introduction to tools in TF-A
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
Web APIs DOM节点
二十六、文件系统API(设备在应用间的共享;目录和文件API)
[merge array] 88 merge two ordered arrays
Merge sort
Acwing 4300. Two operations
Csp-j-2020-excellent split multiple solutions
[轉]: OSGI規範 深入淺出
Add level control and logger level control of Solon logging plug-in
2022上半年全国教师资格证下
A problem and solution of recording QT memory leakage
[allocation problem] 455 Distribute cookies
[to be continued] [UE4 notes] L1 create and configure items
[to be continued] [UE4 notes] L3 import resources and project migration
用STM32点个灯
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
卷积神经网络——卷积层
Acwing 4301. Truncated sequence
[turn to] MySQL operation practice (I): Keywords & functions