Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 1.07 KB

README_EN.md

File metadata and controls

47 lines (38 loc) · 1.07 KB

Binary Search

Algorithm Templates

Template 1

boolean check(int x) {}

int search(int left, int right) {
    while (left < right) {
        int mid = (left + right) >> 1;
        if (check(mid)) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return left;
}

Template 1

boolean check(int x) {}

int search(int left, int right) {
    while (left < right) {
        int mid = (left + right + 1) >> 1;
        if (check(mid)) {
            left = mid;
        } else {
            right = mid - 1;
        }
    }
    return left;
}

Examples