Here, if I do not consider time complexity and space complexity criteria in mind, I tried something.
Here, largest represents the largest element in array and once largest was found, I swapped the largest with the first element of the array and then so I reused the method which I used to find largest in order to Получите метод второй по величине , который я хранил в второй по величине переменной.
Здесь, в идеале я должен получить элемент secondl̥argest в ответ, в то время как я чувствую себя самым большим .
Пожалуйста, помогайте
public static int secondLargest(int[] arr, int size)
{
int largest= arr[0];
for(int i=1; i largest)
{
largest= arr;
}
}
if(largest!= arr[0])
{
int temp= arr[0];
arr[0]= largest;
largest = temp;
}
int SecondLargest = arr[1];
for(int i=2; i SecondLargest)
{
SecondLargest= arr;
}
}
return SecondLargest;
Подробнее здесь: https://stackoverflow.com/questions/734 ... n-an-array
Второй по величине элемент в массиве ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как найти наибольшее и второе по величине число в массиве без использования функции max
Anonymous » » в форуме Php - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-