Đề bài
Xem bản dịchReturn 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.
Ràng buộc
0 ≤ length ≤ 100,000
Ví dụ
Ví dụ 1
Đầu vào:
numbers = [0, 1, 0, 3, 12]
Kết quả mong đợi:
expected = [1, 3, 12, 0, 0]
Đầu vào:
std::vector<long long> numbers = {0, 1, 0, 3, 12};
Kết quả mong đợi:
std::vector<long long> expected = {1, 3, 12, 0, 0};
Đầu vào:
long[] numbers = new long[] {0, 1, 0, 3, 12};
Kết quả mong đợi:
long[] expected = new long[] {1, 3, 12, 0, 0};
Giải thích
1, 3, 12 keep their order and the two zeros go last: [1, 3, 12, 0, 0].
Ví dụ 2
Đầu vào:
numbers = [0, 0]
Kết quả mong đợi:
expected = [0, 0]
Đầu vào:
std::vector<long long> numbers = {0, 0};
Kết quả mong đợi:
std::vector<long long> expected = {0, 0};
Đầu vào:
long[] numbers = new long[] {0, 0};
Kết quả mong đợi:
long[] expected = new long[] {0, 0};
Giải thích
Only zeros: the list stays [0, 0].
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.