โจทย์
ดูฉบับแปลReturn the total of all numbers in the list. An empty list sums to 0.
Implement sum_array(numbers).
Input
numbers: The list of integers.
Output
Return the sum.
เงื่อนไข
0 ≤ length ≤ 100,000; the total fits in a 64-bit integer
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
numbers = [1, 2, 3, 4]
ผลลัพธ์ที่คาดหวัง:
expected = 10
อินพุต:
std::vector<long long> numbers = {1, 2, 3, 4};
ผลลัพธ์ที่คาดหวัง:
long long expected = 10;
อินพุต:
long[] numbers = new long[] {1, 2, 3, 4};
ผลลัพธ์ที่คาดหวัง:
long expected = 10;
คำอธิบาย
1 + 2 + 3 + 4 = 10.
ตัวอย่างที่ 2
อินพุต:
numbers = []
ผลลัพธ์ที่คาดหวัง:
expected = 0
อินพุต:
std::vector<long long> numbers = {};
ผลลัพธ์ที่คาดหวัง:
long long expected = 0;
อินพุต:
long[] numbers = new long[] {};
ผลลัพธ์ที่คาดหวัง:
long expected = 0;
คำอธิบาย
Nothing to add: 0.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน