当前位置:网站首页>An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
2022-08-09 13:54:00 【to raise pigs】
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;
}
}
边栏推荐
猜你喜欢
GIN a preliminary study, the environment is installed
GIN文件上传与返回
5G China unicom AP:B SMS ASCII Transcoding Requirements
WSA工具箱安装应用商店提示无法工作怎么解决?
How to reduce the size of desktop icons after the computer is reinstalled
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
联通网管协议框图
七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
GIN Bind模式获取参数和表单验证
GIN初探,环境安装
随机推荐
基于 R 语言的判别分析介绍与实践 LDA和QDA
陈强教授《机器学习及R应用》课程 第十三章作业
novel research
FFmpeg多媒体文件处理(FFMPEG日志系统)
Rmarkdown Tutorial
leetcode 20. Valid Parentheses 有效的括号(中等)
陈强教授《机器学习及R应用》课程 第十四章作业
30行代码实现微信朋友圈自动点赞
联通网管协议框图
正则表达式-re模块
Yocto 可以下载的第三方库
Process/Thread related in Sandbox - 1
javscript基础易错点集合
FFmpeg multimedia file processing (FFMPEG logging system)
RTSP协议讲解
用plot_hist_numeric()实现画直方图
Professor Chen Qiang "application in machine learning and R" course chapter 17
5G China unicom AP:B SMS ASCII 转码要求
为什么文字不贴合边
FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)