当前位置:网站首页>剑指 Offer 21. 调整数组顺序使奇数位于偶数前面(循环不变量)
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面(循环不变量)
2022-08-09 12:45:00 【养猪去】
class Solution {
public int[] exchange(int[] nums) {
int n = nums.length;
int i = -1, j = 0;
for(; j < n; j++) {
if(nums[j] % 2 == 1) {
int t = nums[++i];
nums[i] = nums[j];
nums[j] = t;
}
}
return nums;
}
}
边栏推荐
- 基于 R 语言的判别分析介绍与实践 LDA和QDA
- Flutter入门进阶之旅(八)Button Widget
- 陈强教授《机器学习及R应用》课程 第十七章作业
- Say goodbye to the AI era of hand looms
- ansible-cmdb friendly display ansible collects host information
- uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)
- 电脑重装系统还原0x80070005错误如何解决
- Rust from entry to proficient 04 - data types
- 单面线路板与精密多层PCB线路板区别有哪些?
- 腾讯发布第二代四足机器人Max,梅花桩上完成跳跃、空翻
猜你喜欢

2022年非一线IT行业就业前景?

kustomize入门示例及基本语法使用说明

Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project

第六届“强网杯”全国网络安全挑战赛

乐东消防救援大队应邀为干部开展消防安全培训

Do you know the difference between comments, keywords, and identifiers?

Jenkins API groovy调用实践: Jenkins Core Api & Job DSL创建项目

Go Affair, How to Become a Gopher and Find a Go Job in 7 Days, Part 1

The FPGA - work summary recently

5G Unicom Network Management Design Ideas
随机推荐
【HCIP持续更新】IS-IS协议原理与配置
电脑重装系统后桌面图标如何调小尺寸
FPGA-在ISE中错误总结(更新中)
Say goodbye to the AI era of hand looms
Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
陈强教授《机器学习及R应用》课程 第十七章作业
handwritten big pile
SQL Server查询优化 (转载非原创)
JVM之配置介绍(一)
Jenkins API groovy调用实践: Jenkins Core Api & Job DSL创建项目
[FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
ERP不规范,同事两行泪 (转载非原创)
jenkins api create custom pipeline
WSA工具箱安装应用商店提示无法工作怎么解决?
中断系统结构及中断控制详解
阿里大淘系模型治理阶段性分享
R 语言 2010.1至2021.12艾滋病每月发病人数 时间序列分析
Redis源码剖析之数据过期(expire)
FPGA中串口通信的时钟频率和波特率计数