当前位置:网站首页>4.调整数组顺序使奇数位于偶数前面
4.调整数组顺序使奇数位于偶数前面
2022-07-28 09:58:00 【[email protected]】
双指针
public int[] exchange(int[] nums) {
int left = 0, right = nums.length - 1;
while(left <= right){
while(left <= right && nums[left] % 2 == 1)
left++;
while(left <= right && nums[right] % 2 == 0)
right--;
if(left > right)
break;
int tmp = nums[left];
nums[left] = nums[right];
nums[right] = tmp;
}
return nums;
}
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124576941
边栏推荐
- 02.1.2.逻辑类型 bool
- 技术人 | 研发效能的思考总结
- uni-app进阶之创建组件/原生渲染
- Description of landingsite electronic label quppa firmware entering DFU status
- 14、双指针——盛最多水的容器
- Voice chat app - how to standardize the development process?
- Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
- 数据库mysql基础
- 并查集
- IE兼容性问题处理
猜你喜欢
随机推荐
基于ModelArts续写最伟大的作品【玩转华为云】
What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system
B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
Performance test of API gateway APIs IX in Google cloud T2a and T2D
12、双指针——合并两个有序链表
我用小程序容器让移动研发效率提升了5倍!
vc链接静态库的时候要注意的问题
Cloudcompare & PCL matching point sampling consistency suppression
15、判断二维数组中是否存在目标值
MySQL架构原理
What are the advantages of MRO purchasing website for industrial products? One article will help you understand
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
什么样的知识付费系统功能,更有利于平台与讲师发展?
JWT 登录认证 + Token 自动续期方案,写得太好了!
uni-app进阶之生命周期
Uni app advanced creation component / native rendering
2022 uni app parsing token standard - use jsrsasign - climb the pit
海量数据TopN问题
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server








