当前位置:网站首页>【模拟】922. Sort Array By Parity II
【模拟】922. Sort Array By Parity II
2022-07-01 00:41:00 【暮色_年华】
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.
题意:重排nums数组,使nums[i]和i奇偶性相同
新开一个数组(用两个指针表示奇数位和偶数为),扫描原数组,如果是奇数,放在奇数位;否则放在偶数位。
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;
}
}边栏推荐
- 孔乙己第一问之服务通信知多少?
- Pre training / transfer learning of models
- Exploration and practice of "flow batch integration" in JD
- MFC TCP communication server client demo notes vs2019
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
- 做生意更加务实
- 【学习笔记】简单dp
- 染色法判断二分图
- (学习力+思考力) x 行动力,技术人成长的飞轮效应总结
- Training discipline principle of robot programming
猜你喜欢

Win11安装redis 数据库以及redis desktop manager的下载

Dls-20 double position relay 220VDC

【网络丢包,网络延迟?这款神器帮你搞定所有!】

Unhandled Exception: MissingPluginException(No implementation found for method launch on channel)
![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]

Green, green the reed. dew and frost gleam.
![[go] go implements row column conversion of sets](/img/d9/6272e55b2d9c6b6fbdf2537773bb83.png)
[go] go implements row column conversion of sets
![Parity linked list [two general directions of linked list operation]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
Parity linked list [two general directions of linked list operation]

Orb-slam2 source code learning (II) map initialization

uniapp官方组件点击item无效,解决方案
随机推荐
系统设置大页
mysql数据库基础:流程控制
Installing mongodb database in Windows Environment
JS方法大全的一个小文档
pytorch编程知识(2)
[network packet loss and network delay? This artifact can help you deal with everything!]
【office办公-pdf篇】pdf合并与拆分让我们摆脱付费软件的功能限制好不好
Exploration and practice of "flow batch integration" in JD
Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base
Training discipline principle of robot programming
双位置继电器DLS-5/2 DC220V
K210 access control complete
StrictMode卡顿与泄漏检测-StrictMode原理(2)
染色法判断二分图
WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
二十多年来第一次!CVPR最佳学生论文授予中国高校学生!
【Qt5-基础篇_1】从0开始,德天老师和你一起学习——窗口简介
K210门禁毕设
Fluent JSON serialization deserialization
sort自定义函数