Easy-22
来源:互联网 发布:ubuntu tty1 登录 编辑:程序博客网 时间:2024/05/22 05:09
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]
.
Note:
- You must do this in-place without making a copy of the array.
- Minimize the total number of operations.
void moveZeroes(int* nums, int numsSize) {
for(int i=numsSize-1;i>=0;i--)
{
if(nums[i]==0)
{
continue;
}
int j;
for(j=i-1;j>=0;j--)
{
if(nums[j]==0)
{
int k=nums[i];
nums[i]=nums[j];
nums[j]=k;
break;
}
}
if(j==-1)
{
return nums;
}
}
return nums;
}
Input:[0,1,0,3,12]
for(int i=0;i<numsSize;i++)
{
if(nums[i]!=0)
{
continue;
}
int j;
for(j=i+1;j<numsSize;j++)
{
if(nums[j]!=0)
{
int k=nums[i];
nums[i]=nums[j];
nums[j]=k;
break;
}
}
if(j==numsSize)
{
return nums;
}
}
return nums;
}
- Easy-22
- easy
- Easy
- Easy-题目22:231. Power of Two
- NHK Easy News 翻译 12月22日-1
- NHK Easy News 翻译 12月22日-2
- NHK Easy News 翻译 12月22日-3
- NHK Easy News 翻译 12月22日-4
- LeetCode-Easy刷题(22)Binary Tree Level Order Traversal II
- Easy Plugs
- easy problem
- So Easy!
- so easy
- easy explorer
- Easy Explore
- Easy Task
- Easy Task
- Easy CHM
- 交叉熵代价函数
- 免费电子邮箱加密证书的申请
- 数值作业:龙贝格算法计算积分C语言实现
- matplotlib.pyplot.subplot
- 向量范数和矩阵范数的定义
- Easy-22
- JSON和JSONP
- gradle环境问题(项目一直Refreshing)原因与解决办法
- C++程序运行时间计算【网上摘抄,方便查询】
- Navicat for MySQL:快捷键整理
- Leetcode学习(16)—— Max Consecutive Ones
- PHP 使用MYSQLI扩展操作数据库
- 线程视图(并行性能)
- 内部排序