/
Andrey_java_edu
/
Algorithms
Обзор
Документация
Войти
/
Andrey_java_edu
/
Algorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/kamenskiy/io/Main.java
31 строка
734 B
AndreyJavaEdu
Init commit
07 апр 2024, 21:05
07 апр 2024, 21:05
b955250
Код
Авторство
О чём код?
package com.kamenskiy.io; public class Main { public static void main(String[] args) { int[] array = {1, 3, 4}; int index = findIndex(array, -1); System.out.println(index); } public static int findIndex(int[] array, int number) { int start = 0; int end = array.length - 1; int curInd; while (true) { curInd = (start + end) / 2; if (array[curInd] == number) { return curInd; } else if (start > end) { return start; } else { if (array[curInd] > number) { end = curInd - 1; }else start = curInd + 1; } } } }