当前位置:网站首页>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
边栏推荐
- 选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步
- OSPF的拓展配置,选路原则,防环及重发布
- CloudCompare&PCL 匹配点采样一致性抑制
- LinkedList源码按摩,啊舒服
- Double pointer technique
- Performance test of API gateway APIs IX in Google cloud T2a and T2D
- Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
- office2013以上输入数学公式
- MySQL架构原理
- SuperMap iServer发布管理以及调用地图服务
猜你喜欢

arthas使用教程
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology

Digital construction of pharmaceutical industry is on the verge

什么样的知识付费系统功能,更有利于平台与讲师发展?

OSPF的拓展配置,选路原则,防环及重发布

In the era of home health diagnosis, Senzo creates enhanced lateral flow test products

JS promotion: the underlying principle of flat tiling

Weekly report on July 27, 2022

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

Joint search set
随机推荐
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
02.1.2.逻辑类型 bool
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
Prometheus 运维工具 Promtool (四)TSDB 功能
office2013以上输入数学公式
Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
TCP Basics
️雄关漫道真如铁,而今迈步从头越️
Weekly report on July 27, 2022
【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03
uni-app进阶之创建组件/原生渲染
SQL server, MySQL master-slave construction, EF core read-write separation code implementation
Holy Grail of web and double wing layout, float, clear, both
arthas使用教程
定了!就在7月30日!
OSPF expansion configuration, routing principles, anti ring and re release
剑指offer
医药行业数字化建设,箭在弦上