32.leetcode题目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.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

想法一,遇到0就删除,同时在尾部插入0

想法2,遇到不为0的就从nums.begin()开始存放,并且记下不为0的个数,最后将后面的置0

但是,两种方法的运行时间都是20ms,最快的是16ms


你可能感兴趣的:(32.leetcode题目283: Move Zeroes)