Problema
Mostra traduzioneReturn the largest value in the list by checking each element once.
Implement array_maximum(numbers).
Input
numbers: A non-empty list of integers.
Output
Return the maximum.
Vincoli
1 ≤ length ≤ 100,000
Esempi
Esempio 1
Input:
numbers = [3, 9, 2]
Output atteso:
expected = 9
Input:
std::vector<long long> numbers = {3, 9, 2};
Output atteso:
long long expected = 9;
Input:
long[] numbers = new long[] {3, 9, 2};
Output atteso:
long expected = 9;
Spiegazione
9 is larger than 3 and 2.
Esempio 2
Input:
numbers = [-4, -1, -7]
Output atteso:
expected = -1
Input:
std::vector<long long> numbers = {-4, -1, -7};
Output atteso:
long long expected = -1;
Input:
long[] numbers = new long[] {-4, -1, -7};
Output atteso:
long expected = -1;
Spiegazione
With only negative values, -1 is the largest.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.