LeetCode算法笔记-Day59
283. Move Zeroes
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
1.You must do this in-place without making a copy of the array.
2.Minimize the total number of operations.
1 | Example: |
方法一:双指针
Analyse:
Answer:
1 | /** |
- 时间复杂度:O(n)
- 空间复杂度:O(1)