当前位置:网站首页>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
边栏推荐
- 海量数据TopN问题
- Illustrate three mainstream enterprise architecture models (recommended collection!)
- leetcode076——数组中的第 k 大的数字
- Double pointer technique
- What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
- 华为入股石墨烯材料厂商富烯科技,持股10%
- 13、哈希表——两个链表第一个公共节点
- uni-app进阶之生命周期
- 双指针技巧
- uni-app进阶之创建组件/原生渲染
猜你喜欢

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

7、二分法——寻找一组重复或者有序但是旋转的数组
![[jzof] 14 cut rope](/img/36/6f58b443a549ad245c1c4cfe5d13af.png)
[jzof] 14 cut rope

初识SuperMap iDesktop

巧用ngx_lua做流量分组

2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了

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

ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天

On July 13, 2021, we collapsed like this

office2013以上输入数学公式
随机推荐
Go json.Decoder Considered Harmful
MySQL的SQL TRACE一例
Context values traps and how to avoid or mitigate these traps in go
UEditor V1.4.3控制文件压缩
[jzof] 15 bits of 1 in binary
Description of landingsite electronic label quppa firmware entering DFU status
华为入股石墨烯材料厂商富烯科技,持股10%
数据库mysql基础
Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST
什么样的知识付费系统功能,更有利于平台与讲师发展?
Prometheus operation and maintenance tool promtool (IV) TSDB function
Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
Leetcode076 -- the kth largest number in the array
软件设计师考前20问,注意啦!!
matlab特征点提取--记录自用
Vulnerability analysis hevd-0x8.integeroverflow[win7x86]
基于docker安装MySQL
[esp32][esp idf] esp32s3 quickly build lvglv7.9
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC
19. 删除链表的倒数第 N 个结点