当前位置:网站首页>The even number of an integer queue is placed in the front, the odd number is placed in the back, and the relative position of the even and odd numbers remains unchanged
The even number of an integer queue is placed in the front, the odd number is placed in the back, and the relative position of the even and odd numbers remains unchanged
2022-07-28 08:03:00 【The galloping snail has been occupied】
Ideas :
Go through the array ,
1. use 2 Pointers from the array header , Tail scan ;
Head pointer check even , Tail pointer check odd ;
2. Use an empty array , To store the scanned even numbers , Odd number ; Even numbers start at the head of the array , Odd numbers start at the end of the array ;
public static void sort(int[] a){
int[] b = new int[a.length];
int m =0;
int n = b.length-1;
for (int i = 0; i <a.length ; i++) {
if(a[i] % 2 ==0){
// even numbers
b[m]=a[i];
m++;
}
if(a[a.length-1-i] %2 !=0){
// Odd number
b[n]=a[a.length-1-i];
n--;
}
}
}
边栏推荐
- GD32使用ST的HAL库和GD官方库的一些体会
- DNA-CuInSeQDs近红外CuInSe量子点包裹脱氧核糖核酸DNA
- After being accidentally dragged into QQ fraud group
- Redis of non relational database [detailed setup of redis cluster]
- DNA-Ag2SQDs脱氧核糖核酸DNA修饰硫化银Ag2S量子点的合成方法
- DNA cuinseqds near infrared CuInSe quantum dots wrapped deoxyribonucleic acid DNA
- MySQL view the memory size of a table
- @The role of documented
- The core packages and middleware required for golang development cover all areas of the project and are worth collecting
- C语言犄角旮旯的知识之指针
猜你喜欢

JUC atomic class: CAS, unsafe, CAS shortcomings, how to solve ABA problems in detail

非关系型数据库之Redis【redis集群详细搭建】

@Documented 的作用

谈谈DOM0,DOM1,DOM2,DOM3

DNA modified rhodium RH nanoparticles rhnps DNA (DNA modified noble metal nanoparticles)

数据化管理洞悉零售及电子商务运营——数据化管理介绍

Which of class A and class B is more stringent in EMC?

Talk about row storage and column storage of database

Copper indium sulfide CuInSe2 quantum dots modified DNA (deoxyribonucleic acid) DNA cuinse2qds (Qiyue)

Rk3568 development board installation system startup
随机推荐
EMC之PCB设计技巧
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
03 | project deployment: how to quickly deploy a website developed based on the laravel framework
PCB design skills of EMC
node(一)
Qt多线程中槽函数在哪个线程里执行分析
EMC's "don't come back until you rectify"
Flowable workflow all business concepts
DNA脱氧核糖核酸修饰金属铂纳米颗粒PtNPS-DNA|科研试剂
非关系型数据库之Redis【redis安装】
DNA修饰金属铑Rh纳米颗粒RhNPS-DNA(DNA修饰贵金属纳米颗粒)
Use ffmpeg to generate single image + single audio streaming video in batches
Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022
谈谈DOM0,DOM1,DOM2,DOM3
ArcGIS JS自定义Accessor,并通过watchUtils相关方法watch属性
演讲笔记 适合所有人的实用程序生成 PCG
Autodesk desktop licensing service error 1067 handling method
细说共模干扰和差模干扰
Daily question - split equal sum subset
Modify the conf file through sed