LeetCode初级算法-数组-8
2019-01-30 12:07
183 查看
题目:移动零
C语言解题
void moveZeroes(int* nums, int numsSize) { int notzero = 0; for (int i = 0; i < numsSize; i++) { if (nums[i] != 0) { nums[notzero] = nums[i]; notzero++; } } for (int i = notzero; i < numsSize; i++) { nums[i] = 0; } }
两个指针指向数组元素,遍历数组nums,nums[i]不为0,就留下覆盖到nums[notzero]。遍历完后,剩下的数组元素改为0。
相关文章推荐
- LeetCode初级算法-数组-10
- LeetCode-探索-初级算法-数组-从排序数组中删除重复项-java
- LeetCode(初级算法)数组篇--存在重复c++
- LeetCode初级算法-数组-11
- LeetCode(初级算法)数组篇--只出现一次的数字c++
- leetcode 初级算法数组8 移动0
- LeetCode(初级算法)数组篇--两个数组的交集II c++
- LeetCode初级算法-数组-9
- Leetcode初级算法6两个数组的交集
- LeetCode初级算法数组9 两数之和
- LeetCode初级算法-数组-旋转数组(python)
- LeetCode探索模块初级算法数组章节python3代码实现
- LeetCode(初级算法)数组篇-移动零
- leetcode初级算法数组11 旋转图像
- LeetCode(初级算法)数组篇--从排序数组中删除重复项c++
- LeetCode(初级算法)数组篇--买卖股票的最佳时机 II c++
- leetcode 初级算法数组7加一
- LeetCode(初级算法)数组篇--旋转数组c++
- LeetCode(初级算法)数组篇--加一c++
- 【LeetCode-面试算法经典-Java实现】【154-Find Minimum in Rotated Sorted Array II(找旋转数组中的最小数字II)】