โจทย์
ดูฉบับแปลReturn 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.
เงื่อนไข
1 ≤ length ≤ 100,000
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
numbers = [3, 9, 2]
ผลลัพธ์ที่คาดหวัง:
expected = 9
อินพุต:
std::vector<long long> numbers = {3, 9, 2};
ผลลัพธ์ที่คาดหวัง:
long long expected = 9;
อินพุต:
long[] numbers = new long[] {3, 9, 2};
ผลลัพธ์ที่คาดหวัง:
long expected = 9;
คำอธิบาย
9 is larger than 3 and 2.
ตัวอย่างที่ 2
อินพุต:
numbers = [-4, -1, -7]
ผลลัพธ์ที่คาดหวัง:
expected = -1
อินพุต:
std::vector<long long> numbers = {-4, -1, -7};
ผลลัพธ์ที่คาดหวัง:
long long expected = -1;
อินพุต:
long[] numbers = new long[] {-4, -1, -7};
ผลลัพธ์ที่คาดหวัง:
long expected = -1;
คำอธิบาย
With only negative values, -1 is the largest.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน