当前位置:网站首页>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];
}
}
边栏推荐
- Golang面试整理 三 简历如何书写
- 开户哪家券商比较好?网上开户安全吗
- gtest从一无所知到熟练使用(2)什么是测试夹具/装置(test fixture)
- HDU - 1078 fatmouse and cheese (memory search DP)
- [early knowledge of activities] list of recent activities of livevideostack
- Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
- Numpy vstack and column_ stack
- WGCNA analysis basic tutorial summary
- Solve the problem of data disorder caused by slow asynchronous interface
- Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
猜你喜欢

Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history

Flutter TextField示例

OMS系统实战的三两事

Case sharing | integrated construction of data operation and maintenance in the financial industry

超详细教程,一文入门Istio架构原理及实战应用

Word文档中标题前面的黑点如何去掉

How to use concurrentlinkedqueue as a cache queue

Enlightenment of maker thinking in Higher Education

QT—双缓冲绘图
![[optimtool.unconstrained] unconstrained optimization toolbox](/img/ef/65379499df205c068ee9bc9df797ac.png)
[optimtool.unconstrained] unconstrained optimization toolbox
随机推荐
HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
numpy vstack 和 column_stack
超详细教程,一文入门Istio架构原理及实战应用
Maidong Internet won the bid of Beijing life insurance
Lambdaquerywrapper usage
Interpreting the development of various intelligent organizations in maker Education
做BI开发,为什么一定要熟悉行业和企业业务?
Kubeadm初始化报错:[ERROR CRI]: container runtime is not running
开源之夏专访|Apache IoTDB社区 新晋Committer谢其骏
Which securities company is better to open an account? Is online account opening safe
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
Jerry's ad series MIDI function description [chapter]
How to implement Devops with automatic tools
GTEST from ignorance to skillful use (1) GTEST installation
Why does invariant mode improve performance
置信区间的画法
gtest从一无所知到熟练使用(4)如何用gtest写单元测试
Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
开户哪家券商比较好?网上开户安全吗