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 satisfi…
给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数. 对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数:当 A[i] 为偶数时, i 也是偶数. 你可以返回任何满足上述条件的数组作为答案. 示例: 输入:[4,2,5,7] 输出:[4,5,2,7] 解释:[4,7,2,5],[2,5,4,7],[2,7,4,5] 也会被接受. 提示: 2 <= A.length <= 20000 A.length % 2 == 0 0 <= A[i] <= 1000 clas…
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 re…
https://leetcode.com/problems/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…
题目要求 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 sa…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: SortArrayByParityII * @Author: xiaof * @Description: 922. Sort Array By Parity II * Given an array A of non-negative integers, half of the…
problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArrayByParityII(vector<int>& A) { int n = A.size(); , j=; i<n, j<n; ) { ==) i += ; ==) j += ; if(j<n) swap(A[i], A[j]); } return A; } }; 参考 1…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用奇偶数组 排序 奇偶数位置变量 日期 题目地址: https://leetcode.com/problems/sort-array-by-parity-ii 题目描述 Given an array A of non-negative integers, half of the integers in A are odd, and half of…
题目如下: 解题思路:非常简单的题目,引入两个变量oddInx = 1和evenInx = 0,和与A等长的结果数组res.然后遍历A,如果A[i]为偶数,则令res[evenInx] = A[i],evenInx += 2:否则令res[oddInx] = A[i],evenInx += 2. 代码如下: class Solution(object): def sortArrayByParityII(self, A): """ :type A: List[int] :rty…
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 condit…