当前位置:网站首页>4. Adjust the array order so that odd numbers precede even numbers
4. Adjust the array order so that odd numbers precede even numbers
2022-07-28 10:16:00 【[email protected]】
Double pointer
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://yzsam.com/2022/209/202207280958224749.html
边栏推荐
- 【JZOF】15二进制中1的位数
- 数据库mysql基础
- 【云驻共创】企业数字化转型,华为云咨询与你同行
- SuperMap iServer发布管理以及调用地图服务
- Description of landingsite electronic label quppa firmware entering DFU status
- pt-kill 查询中包含中文字符 导致工具失效的排查
- Detailed explanation of super complete knowledge points of instruction system
- OSPF expansion configuration, routing principles, anti ring and re release
- What are the advantages of MRO purchasing website for industrial products? One article will help you understand
- Prometheus 运维工具 Promtool (四)TSDB 功能
猜你喜欢

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

剑指offer
![[jzof] 14 cut rope](/img/36/6f58b443a549ad245c1c4cfe5d13af.png)
[jzof] 14 cut rope

二维前缀和

15、判断二维数组中是否存在目标值

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

gcc: error trying to exec 'as': execvp: No such file or directory
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

Redis面试题必知必会

2022 uni app parsing token standard - use jsrsasign - climb the pit
随机推荐
16、字符串反转
Performance test of API gateway APIs IX in Google cloud T2a and T2D
关于软考高级要不要报班学习
传全球半导体设备巨头或将于上海建合资工厂!
Qt | 信号和槽的一些总结
centos7下安装mysql,网上文章都不太准
Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
剑指offer
排序——快速排序(快慢指针实现)
死锁算法:银行家算法和安全性算法
LinkedList source massage, ah comfortable
[esp32][esp idf] esp32s3 quickly build lvglv7.9
漏洞分析丨HEVD-0x8.IntegerOverflow[win7x86]
On July 13, 2021, we collapsed like this
基于ModelArts续写最伟大的作品【玩转华为云】
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC
Voice chat app - how to standardize the development process?
Deadlock algorithm: banker algorithm and security algorithm
初识SuperMap iDesktop
Talk about the problem of preventing others from debugging websites through console based on JS implementation