当前位置:网站首页>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
边栏推荐
- 软件设计师考前20问,注意啦!!
- B2B e-commerce website scheme for building materials industry: enable the transformation and upgrading of building materials enterprises to achieve cost reduction and efficiency improvement
- 【学习笔记】border与period
- Thinking and summary of technical personnel | R & D Efficiency
- 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
- [jzof] 15 bits of 1 in binary
- 语音聊天app——如何规范开发流程?
- Prometheus operation and maintenance tool promtool (IV) TSDB function
- Sizebasedtriggingpolicy introduction
- Holy Grail of web and double wing layout, float, clear, both
猜你喜欢

并查集
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

Digital construction of pharmaceutical industry is on the verge

What are the advantages of MRO purchasing website for industrial products? One article will help you understand

office2013以上输入数学公式

TCP Basics

6、双指针——递增数组两数之和与目标数相等

LSA and optimization of OSPF

为什么要考一级建造师,一建证书含金量有多高?

Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
随机推荐
On July 13, 2021, we collapsed like this
In retaliation for the dismissal of the company, I changed all code comments of the project!
Prometheus 运维工具 Promtool (四)TSDB 功能
vc链接静态库的时候要注意的问题
Function introduction and description of @jsontype annotation in fastjson
CloudCompare&PCL 匹配点采样一致性抑制
16、字符串反转
Elk real time log analysis platform
记录一次idea中的父子项目修改project与module名称,亲测!
二分、三分、01分数规划【第III弹】
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
为什么要考一级建造师,一建证书含金量有多高?
PHP生成二维码(学习)
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
二分、三分、01分数规划 【第I弹】
初识SuperMap iDesktop
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
Which strings will be resolved to null by fastjason?
Kubernetes
医药行业数字化建设,箭在弦上