当前位置:网站首页>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
边栏推荐
- select如果不加order by子句,返回结果的顺序是不可靠的
- Irregular area of OSPF, LSA and serial number
- 不登高山,不知天之高也;不临深溪,不知地之厚也
- 安装gmp
- 为什么要考一级建造师,一建证书含金量有多高?
- Flink - checkpoint Failure reason: Not all required tasks are currently running
- 广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!
- What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system
- Which strings will be resolved to null by fastjason?
- Holy Grail of web and double wing layout, float, clear, both
猜你喜欢

软件设计师考前20问,注意啦!!

图解 3 种主流企业架构模式(建议收藏!)

Redis面试题必知必会

我用小程序容器让移动研发效率提升了5倍!

Weekly report on July 27, 2022

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control

arthas使用教程

19. 删除链表的倒数第 N 个结点

二分、三分、01分数规划 【第I弹】

Illustrate three mainstream enterprise architecture models (recommended collection!)
随机推荐
arthas使用教程
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
select如果不加order by子句,返回结果的顺序是不可靠的
OSPF的不规则区域,LSA和序列号
SkiaSharp 之 WPF 自绘 拖曳小球(案例版)
Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
Double pointer technique
线程同步volatile与synchronized详解
Introduction to timebasedrollingpolicy
Weekly report on July 27, 2022
Flink - checkpoint Failure reason: Not all required tasks are currently running
(1)机器学习概念总结
关于软考高级要不要报班学习
leetcode076——数组中的第 k 大的数字
二分、三分、01分数规划 【第I弹】
初识SuperMap iDesktop
It's settled! On July 30!
Digital construction of pharmaceutical industry is on the verge
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系