当前位置:网站首页>Force deduction solution summary 905- array sorted by parity
Force deduction solution summary 905- array sorted by parity
2022-06-12 02:07:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link : Power button
describe :
Give you an array of integers nums, take nums Move all even elements in the array to the front of the array , Followed by all odd elements .
Returns... That meets this condition Any array As the answer .
Example 1:
Input :nums = [3,1,2,4]
Output :[2,4,3,1]
explain :[4,2,3,1]、[2,4,1,3] and [4,2,1,3] It will also be seen as the right answer .
Example 2:
Input :nums = [0]
Output :[0]
Tips :
1 <= nums.length <= 5000
0 <= nums[i] <= 5000
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/sort-array-by-parity
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * Traverse twice , Find the even number for the first time , Find the odd number for the second time
Code :
public class Solution905 {
public int[] sortArrayByParity(int[] nums) {
int[] result = new int[nums.length];
int index = 0;
for (int i = 0; i < nums.length; i++) {
int num = nums[i];
if (num % 2 == 0) {
result[index++] = num;
}
}
for (int i = 0; i < nums.length; i++) {
int num = nums[i];
if (num % 2 != 0) {
result[index++] = num;
}
}
return result;
}
}边栏推荐
- The release of star ring kundb 2.2 provides a new choice for business systems with high concurrent transactions and queries
- Modification of system module information of PHP security development 12 blog system
- virsh创建/关闭/停止虚拟机常用的几条指令
- How to restore the redis cluster and retain the complete cluster data after changing the node IP
- 如何定位关键词使得广告精准投放。
- [adjustment] notice on the opening of the 2022 pre adjustment system for postgraduate enrollment of Shanghai Second University of Technology
- “中国东信杯”广西大学第四届程序设计竞赛(同步赛)
- Installing mysql-5.7 for Linux (centos7)
- 力扣解法汇总449-序列化和反序列化二叉搜索树
- 竞价广告每次点击出价多少钱是固定的吗?
猜你喜欢

UE4\UE5触摸屏touch事件:单指、双指

Three main factors determining advertising quality

Four schemes for redis to implement message queue

Google Ads 竞价的运作机制

MySQL表常用操作思维导图

Knowledge points of mall development

Smartbi helps you solve the problem of losing high-value customers

How to automatically color cells in Excel

C language programming classic games - minesweeping

商城开发知识点
随机推荐
LeetCode Algorithm 1791. Find the central node of the star chart
Explore performance optimization! Performance improvement from 2 months to 4 hours!
The establishment and introduction of the announcement module of PHP development blog system
Modification of system module information of PHP security development 12 blog system
A mystery of the end of vagrant up
Graphic data analysis | business cognition and data exploration
Fatal error in launcher: unable to create process using
Google 搜索广告系列设置前有哪些准备工作?
力扣解法汇总-剑指 Offer II 114. 外星文字典
Google Ads 的优势
State owned assets into shares, has Jianye real estate stabilized?
How to stop anti-virus software from blocking a web page? Take gdata as an example
ozzanimation-基於sse的動作系統
In Net platform using reflectiondynamicobject to optimize reflection calling code
Smartbi helps you solve the problem of losing high-value customers
阿里云oss文件上传系统
Installing mysql-5.7 for Linux (centos7)
xcall 集群脚本(查看jps命令)
How to maximize the use of various matching methods—— Google SEM
UE4\UE5触摸屏touch事件:单指、双指