当前位置:网站首页>[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;
}
}边栏推荐
- OCR的一些项目
- Analyze the maker education path integrating the essence of discipline
- sort自定义函数
- visual studio 2019 下载
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
- gin_gorm
- JS to convert numbers into Chinese characters for output
- 图的连通性基础
- ASCII、Unicode、GBK、UTF-8之间的关系
- K210 access control complete
猜你喜欢

Interpreting the scientific and technological literacy contained in maker Education

Introduction and principle analysis of cluster and LVS

Construction and beautification of personal blog

Docker deployment MySQL 8

DC學習筆記正式篇之零——綜述與基本流程介紹

Solve idea:class' xxx 'not found in module' xxx‘

uniapp官方组件点击item无效,解决方案

数字IC设计流程总结

图的连通性基础

3dsmax插件开发遍历节点对象和Object获取及INode变换矩阵说明
随机推荐
Poor students can also play raspberry pie
JS to convert numbers into Chinese characters for output
Service grid ASM year end summary: how do end users use the service grid?
Double position relay dls-5/2 dc220v
Two position relay st2-2l/ac220v
系统设置大页
【动态规划】路径dp:931. Minimum Falling Path Sum
What are the functions of soil microorganisms in microbial detection?
Strictmode analysis activity leakage -strictmode principle (3)
短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
Matlab farthest point sampling (FPS improved version)
[deepin] common sets
使用StrictMode-StrictMode原理(1)
Call the classic architecture and build the model based on the classic
Pre training / transfer learning of models
Dls-20 double position relay 220VDC
二季度最后一天
Interpreting the scientific and technological literacy contained in maker Education
Unknown database连接数据库错误
DC学习笔记正式篇之零——综述与基本流程介绍