当前位置:网站首页>283. 移动零-c与语言辅助数组法
283. 移动零-c与语言辅助数组法
2022-07-04 21:23:00 【Mr Gao】
283. 移动零-c与语言辅助数组法
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
请注意 ,必须在不复制数组的情况下原地对数组进行操作。
示例 1:
输入: nums = [0,1,0,3,12]
输出: [1,3,12,0,0]
示例 2:
输入: nums = [0]
输出: [0]
对于这一题,我们可以有很多算法去处理这个题目,但是个人解以,还是使用常规一些的方法,这样不容易出意外,在考试中或者面试中可以快速并简单的解决问题,解题代码如下:
void moveZeroes(int* nums, int numsSize){
int aid[numsSize];
int size1=0;
int size2=0;
int i;
for(i=0;i<numsSize;i++){
if(nums[i]!=0){
nums[size1++]=nums[i];
}
else{
aid[size2++]=nums[i];
}
}
for(i=0;i<size2;i++){
nums[size1++]=aid[i];
}
}
边栏推荐
- CloudCompare&Open3D DBSCAN聚类(非插件式)
- 哈希表(Hash Tabel)
- 股票开户佣金最低多少,炒股开户佣金最低网上开户安全吗
- Bookmark
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- Solve the problem of data disorder caused by slow asynchronous interface
- Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
- 旋变串判断
- GTEST from ignorance to skillful use (1) GTEST installation
- Open3D 曲面法向量计算
猜你喜欢
随机推荐
Jerry's ad series MIDI function description [chapter]
GTEST from ignorance to proficient use (2) what is test fixture
Golang面试整理 三 简历如何书写
Acwing 2022 daily question
Shutter textfield example
GTEST from ignorance to skillful use (1) GTEST installation
Hash table
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
案例分享|金融业数据运营运维一体化建设
Word文档中标题前面的黑点如何去掉
Redis has three methods for checking big keys, which are necessary for optimization
QT—绘制其他问题
Redis03 - network configuration and heartbeat mechanism of redis
Compréhension approfondie du symbole [langue C]
redis RDB AOF
改善机器视觉系统的方法
迈动互联中标北京人寿保险
new IntersectionObserver 使用笔记
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
Numpy vstack and column_ stack