当前位置:网站首页>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;
}
}
边栏推荐
- 浅谈JVM(面试常考)
- 软件测试 -- 0 序
- Haut OJ 1357: lunch question (I) -- high precision multiplication
- Solon Logging 插件的添加器级别控制和日志器的级别控制
- Pointnet++学习
- MySQL数据库(一)
- Haut OJ 1245: large factorial of CDs --- high precision factorial
- Haut OJ 1352: string of choice
- [binary search] 34 Find the first and last positions of elements in a sorted array
- Summary of Haut OJ 2021 freshman week
猜你喜欢
随机推荐
Haut OJ 1243: simple mathematical problems
[allocation problem] 135 Distribute candy
二十六、文件系统API(设备在应用间的共享;目录和文件API)
[轉]: OSGI規範 深入淺出
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
A problem and solution of recording QT memory leakage
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
Web APIs DOM节点
Mysql database (I)
FVP和Juno平台的Memory Layout介绍
xftp7与xshell7下载(官网)
远程升级怕截胡?详解FOTA安全升级
Merge sort
[depth first search] 695 Maximum area of the island
剑指 Offer 06.从头到尾打印链表
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
room数据库的使用
Haut OJ 1401: praise energy
Control Unit 控制部件
YOLOv5添加注意力机制







![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
