Đề bài
Xem bản dịchReturn 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.
Ràng buộc
1 ≤ length ≤ 100,000
Ví dụ
Ví dụ 1
Đầu vào:
numbers = [3, 9, 2]
Kết quả mong đợi:
expected = 9
Đầu vào:
std::vector<long long> numbers = {3, 9, 2};
Kết quả mong đợi:
long long expected = 9;
Đầu vào:
long[] numbers = new long[] {3, 9, 2};
Kết quả mong đợi:
long expected = 9;
Giải thích
9 is larger than 3 and 2.
Ví dụ 2
Đầu vào:
numbers = [-4, -1, -7]
Kết quả mong đợi:
expected = -1
Đầu vào:
std::vector<long long> numbers = {-4, -1, -7};
Kết quả mong đợi:
long long expected = -1;
Đầu vào:
long[] numbers = new long[] {-4, -1, -7};
Kết quả mong đợi:
long expected = -1;
Giải thích
With only negative values, -1 is the largest.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.