2024/11/12 灵茶题单 二分查找
This commit is contained in:
parent
06fc23ec9f
commit
fcc6fec024
|
@ -7,6 +7,12 @@ import org.junit.Test;
|
||||||
* @date: 2024/11/12
|
* @date: 2024/11/12
|
||||||
*/
|
*/
|
||||||
public class Num2529 {
|
public class Num2529 {
|
||||||
|
/**
|
||||||
|
* @Author Cool
|
||||||
|
* @Date 18:50 2024/11/12
|
||||||
|
* 找到第一个0,若存在则找最后一个0的位置,类似于<a herf="https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/description/"/>
|
||||||
|
* 若找不到0,则可能是数组内所有数字都小于0,或是不存在0,则进行分类讨论
|
||||||
|
**/
|
||||||
public int maximumCount(int[] nums) {
|
public int maximumCount(int[] nums) {
|
||||||
int start = binarySearch(nums, 0);
|
int start = binarySearch(nums, 0);
|
||||||
if (start < nums.length && nums[start] == 0) {
|
if (start < nums.length && nums[start] == 0) {
|
||||||
|
|
Loading…
Reference in New Issue