검은 Offer-53을 참조하여 정렬 된 배열에서 I 번호를 찾습니다.

public int search (int [] nums, int target) { 
    // 找 target 的 右边 界-target-1 的 右边 界
    return helper (nums, target) -helper (nums, target-1); 
} 
int helper (int [] nums, int tar) { 
    int i = 0; 
    int j = nums.length-1; 
    // 二分法 查找
    while (i <= j) { 
        int m = (i + j) / 2; 
        if (nums [m] <= tar) { 
            i = m + 1; 
        } 그렇지 않으면 { 
            j = m-1; 
        } 
    } 
    return i; 
}

추천

출처blog.csdn.net/a792396951/article/details/114140484