【Leetcode算法】- Move Zeroes
来源:互联网 发布:北斗卫星定位精度知乎 编辑:程序博客网 时间:2024/06/05 18:37
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].
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
链接:https://leetcode.com/problems/move-zeroes/
方法一:
%% C++class Solution {public: void moveZeroes(vector<int>& nums) { int j = 0; for(int i=0;i<nums.size();i++) if(nums[i]!=0){ nums[j]=nums[i]; j++; } for(;j<nums.size();j++) nums[j] = 0; }};
备注:可能代码不规范,我是顺便学C++
1 0
- 【Leetcode算法】- Move Zeroes
- leetcode 283: Move Zeroes
- leetcode - Move Zeroes
- Leetcode: Move Zeroes
- LeetCode - Move Zeroes
- LeetCode-Move Zeroes
- [LeetCode]Move Zeroes
- leetcode-283-Move Zeroes
- [leetcode 283]Move Zeroes
- LeetCode---Move Zeroes
- LeetCode 283----Move Zeroes
- LeetCode Move Zeroes
- LeetCode Move Zeroes
- Leetcode #283 Move Zeroes
- leetcode: (283) Move Zeroes
- [LeetCode 283] Move Zeroes
- 【LeetCode】Move Zeroes
- LeetCode-Move Zeroes
- Canonical Correlation Analysis 典型相关分析
- Mybatis系列(七)关联映射
- C++ core guidelines -- P.1. -- 直接在代码中表达你的想法
- linux内存管理之内存映射
- linux内存管理之DMA
- 【Leetcode算法】- Move Zeroes
- HDOJ 题目5442 Favorite Donut(后缀数组)
- Robert C. Martin列举的专业软件开发人员必须精通的技能
- 1205 Constructing Roads In JGShining's Kingdom【lis】
- java环境变量的作用与配置
- 浅谈socket
- android增强ImageView
- zookeeper客户端脚本
- HDOJ A+B for Input-Output Practice (I) 问题