โจทย์
ดูฉบับแปลReturn the list with all zeros moved to the end. The non-zero values keep their relative order.
Implement move_zeroes(numbers).
Input
numbers: The list of integers.
Output
Return the rearranged list.
เงื่อนไข
0 ≤ length ≤ 100,000
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
numbers = [0, 1, 0, 3, 12]
ผลลัพธ์ที่คาดหวัง:
expected = [1, 3, 12, 0, 0]
อินพุต:
std::vector<long long> numbers = {0, 1, 0, 3, 12};
ผลลัพธ์ที่คาดหวัง:
std::vector<long long> expected = {1, 3, 12, 0, 0};
อินพุต:
long[] numbers = new long[] {0, 1, 0, 3, 12};
ผลลัพธ์ที่คาดหวัง:
long[] expected = new long[] {1, 3, 12, 0, 0};
คำอธิบาย
1, 3, 12 keep their order and the two zeros go last: [1, 3, 12, 0, 0].
ตัวอย่างที่ 2
อินพุต:
numbers = [0, 0]
ผลลัพธ์ที่คาดหวัง:
expected = [0, 0]
อินพุต:
std::vector<long long> numbers = {0, 0};
ผลลัพธ์ที่คาดหวัง:
std::vector<long long> expected = {0, 0};
อินพุต:
long[] numbers = new long[] {0, 0};
ผลลัพธ์ที่คาดหวัง:
long[] expected = new long[] {0, 0};
คำอธิบาย
Only zeros: the list stays [0, 0].
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน