当前位置:网站首页>Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
2022-07-02 17:12:00 【anieoo】
Original link : The finger of the sword Offer 21. Adjust the array order so that the odd Numbers precede the even Numbers
solution:
class Solution {
public:
vector<int> exchange(vector<int>& nums) {
int n = nums.size();
for(int i = 0,j = 0;i < n;i++) {
if(nums[i] % 2 != 0) swap(nums[i],nums[j++]);
}
return nums;
}
};
边栏推荐
- The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
- 七张图,学会做有价值的经营分析
- Seven charts, learn to do valuable business analysis
- PWM breathing lamp
- GeoServer:发布PostGIS数据源
- Masa framework - DDD design (1)
- QStyle实现自绘界面项目实战(二)
- 【Leetcode】13. Roman numeral to integer
- 绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
猜你喜欢
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
如何与博格华纳BorgWarner通过EDI传输业务数据?
OpenHarmony如何启动远程设备的FA
[leetcode] 14. Préfixe public le plus long
Leetcode1380: lucky numbers in matrix
数字IC手撕代码--投票表决器
Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
13、Darknet YOLO3
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
随机推荐
剑指 Offer 27. 二叉树的镜像
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
智能垃圾桶(五)——点亮OLED
vscode设置删除行快捷键[通俗易懂]
Use of openpose
IP address translation address segment
Serial port controls steering gear rotation
TCP congestion control details | 2 background
学习周刊-总第60期-2022年第25周
VMware install win10 image
MySQL port
酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
【Leetcode】14. 最长公共前缀
PWM breathing lamp
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
Linux Installation PostgreSQL + Patroni cluster problem
2322. 从树中删除边的最小分数(异或和&模拟)
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東