当前位置:网站首页>剑指 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;
}
}
边栏推荐
- [FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
- Redis源码剖析之跳表(skiplist)
- ViewPager fragments of nested data blank page abnormal problem analysis
- 陈强教授《机器学习及R应用》课程 第十七章作业
- 数据挖掘-05
- 在已打开图片上加水印(文字)
- telnet+ftp to control and upgrade the device
- 正则引擎的几种分类
- 用场景定义硬件,英码科技破解“边缘计算”密码
- Dry+Bean+Dataset R语言数据分析,报告英文
猜你喜欢
随机推荐
World's 4th mad scientist dies on his 103rd birthday
5G China unicom AP:B SMS ASCII Transcoding Requirements
JVM之配置介绍(一)
Flutter Getting Started and Advanced Tour (1) - Getting to Know Flutter
陈强教授《机器学习及R应用》课程 第十五章作业
kustomize入门示例及基本语法使用说明
自定义VIEW实现应用内消息提醒上下轮播
中断系统结构及中断控制详解
面试题精选:神奇的斐波那契数列
Yocto 可以下载的第三方库
陈强教授《机器学习及R应用》课程 第十八章作业
Say goodbye to the AI era of hand looms
注释、关键字、标识符的区别你知道吗?
乐东消防救援大队应邀为干部开展消防安全培训
Flutter Getting Started and Advanced Tour (4) Text Input Widget TextField
Report: The number of students who want to learn AI has increased by 200%, and there are not enough teachers
Dry+Bean+Dataset R语言数据分析,报告英文
Flutter入门进阶之旅(十)Dialog&Toast
Ten minutes to teach you how to use VitePress to build and deploy a personal blog site
#WeArePlay | 与更多开发者一起,探索新世界