当前位置:网站首页>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;
}
}
边栏推荐
- A problem and solution of recording QT memory leakage
- Developing desktop applications with electron
- Control Unit 控制部件
- Fragment addition failed error lookup
- [speed pointer] 142 circular linked list II
- Yolov5 ajouter un mécanisme d'attention
- Acwing 4301. Truncated sequence
- Introduction to tools in TF-A
- YOLOv5添加注意力機制
- Mysql database (I)
猜你喜欢

Pointnet++ learning

剑指 Offer 05. 替换空格

Service fusing hystrix

On-off and on-off of quality system construction

Gbase database helps the development of digital finance in the Bay Area

National teacher qualification examination in the first half of 2022

Binary search basis

Hang wait lock vs spin lock (where both are used)

支持多模多态 GBase 8c数据库持续创新重磅升级

TF-A中的工具介绍
随机推荐
sync. Interpretation of mutex source code
浅谈JVM(面试常考)
Bubble sort summary
[to be continued] [UE4 notes] L1 create and configure items
xftp7与xshell7下载(官网)
服务熔断 Hystrix
Zzulioj 1673: b: clever characters???
Add level control and logger level control of Solon logging plug-in
MySQL数据库(一)
Control Unit 控制部件
Solon Auth 认证框架使用演示(更简单的认证框架)
On-off and on-off of quality system construction
Reflection summary of Haut OJ freshmen on Wednesday
YOLOv5-Shufflenetv2
Haut OJ 1357: lunch question (I) -- high precision multiplication
Haut OJ 1218: maximum continuous sub segment sum
[merge array] 88 merge two ordered arrays
二十六、文件系统API(设备在应用间的共享;目录和文件API)
剑指 Offer 58 - II. 左旋转字符串
Count sort