283. 移动零
This commit is contained in:
11
test004.cpp
Normal file
11
test004.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
void moveZeroes(vector<int>& nums) {
|
||||||
|
int len = nums.size();
|
||||||
|
int index = 0;
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
if(nums[i]) nums[index++] = nums[i];
|
||||||
|
}
|
||||||
|
while(index < len) nums[index++] = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user