当前位置:网站首页>[simulation] 922 Sort Array By Parity II
[simulation] 922 Sort Array By Parity II
2022-07-01 01:30:00 【Twilight_ years】
Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
Return any answer array that satisfies this condition.
The question : rearrangement nums Array , send nums[i] and i Parity is the same
Open a new array ( Use two pointers to indicate that odd and even numbers are ), Scan original array , If it's odd , Put it in the odd number ; Otherwise, put it in even digits .
class Solution {
public int[] sortArrayByParityII(int[] nums) {
int[] t=new int[nums.length];
for(int i=0,j=0,k=1;i<nums.length;i++){
if(nums[i]%2==0){
t[j]=nums[i];
j+=2;
}else{
t[k]=nums[i];
k+=2;
}
}
return t;
}
}边栏推荐
- Applet Custom Grid
- Complete software development process
- Install redis database and download redis Desktop Manager in win11
- Service grid ASM year end summary: how do end users use the service grid?
- Orb-slam2 source code learning (II) map initialization
- 为什么要搭建个人博客
- Strictmode jamming and leakage detection -strictmode principle (2)
- StrictMode分析Activity泄漏-StrictMode原理(3)
- ASCII、Unicode、GBK、UTF-8之间的关系
- User defined annotation implementation verification
猜你喜欢

元宇宙为 VR/AR 带来的新机会
![Parity linked list [two general directions of linked list operation]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
Parity linked list [two general directions of linked list operation]

Xjy-220/43ac220v static signal relay

Looksrare team's "cash out" caused disturbance
![[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号](/img/51/e48e222c14f4a4e9f2be91a677033f.png)
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号

Windows环境下安装MongoDB数据库

Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.

Uniapp official component clicking item is invalid, solution
![Split the linked list [take next first and then cut the linked list to prevent chain breakage]](/img/eb/708ab20c13df75f4dbd2d6461d3602.png)
Split the linked list [take next first and then cut the linked list to prevent chain breakage]

Zero of DC learning notes -- overview and basic process introduction
随机推荐
Inspire students' diversified thinking with steam Education
【qt5-tab标签精讲】Tab标签及内容分层解析
Service grid ASM year end summary: how do end users use the service grid?
Construction and beautification of personal blog
The liquor and tourism sector recovers, and Yaduo continues to dream of listing. How far is it from "the first share of the new accommodation economy"?
C# 自定义并动态切换光标
微生物检测,土壤微生物的作用有哪些?
System.CommandLine版CSRebot
Call the classic architecture and build the model based on the classic
微研所,微生物检验中常用的生化反应
Locking relay ydb-100, 100V
Chromatic judgement bipartite graph
About vctk datasets
Zero of DC learning notes -- overview and basic process introduction
Poor students can also play raspberry pie
Dls-42/6-4 dc110v double position relay
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
visual studio 2019 下载
使用 C# 创造 ASCII 艺术
Introduction and principle analysis of cluster and LVS