此解法的时间复杂度是O(N),空间复杂度是O(N)。 publicint[] sortArrayByParity2(int[] A) {intn=A.length, index =0;int[] result =newint[n];for(inti=0; i<n; i++) {if(A[i]%2==0) { result[index++] = A[i]; } }for(intj=0; j<n; j++) {if(A[j]%2!=0) { result[...
} public void swap(int [] Array,int i,int j){ int temp=Array[i]; Array[i]=Array[j]; Array[j]=temp; }
Sort Array By Parity II Leetcode学习笔记:#922. Sort Array By Parity II Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd,......
int* sortArrayByParity(int* nums, int numsSize, int* returnSize) { int *res = (int *)malloc(sizeof(int) * numsSize), index = 0; for (int i = 0; i < numsSize; i++) { if (nums[i] % 2 == 0) { res[index++] = nums[i]; } } for (int i = 0; i < numsSize; ...
LeetCode-922. Sort Array By Parity II i++文章分类运维 Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; ...
922. Sort Array By Parity II # 题目# Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return any answer...
LeetCode-Sort Array By Parity Description: Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this condition....
Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return any answer array that satisfies this condition. Exampl...
leetCode/Array/SortArrayByParityII.py/ Jump to 47 lines (32 sloc)997 Bytes RawBlame """ Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i...
class Solution: def sortArrayByParity(self, A: List[int]) -> List[int]: odd=[] #存奇数 even=[]#存偶数 for i in A: if i%2==1: odd.append(i) else: even.append(i) A=even+odd return A 1217. 玩筹码 数轴上放置了一些筹码,每个筹码的位置存在数组 chips 当中。你可以对 任何筹码 ...