给定一个非负整数数组 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…
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…
""" 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 arra…
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…
Question 992. Sort Array By Parity II Solution 题目大意:给一个int数组,一半是奇数一半是偶数,分别对偶数数和奇数数排序并要求这个数本身是偶数要放在偶数位上 思路:把奇数数和偶数数筛选出来后对其分别排序,再按奇偶索引放到原数组上 Java实现: public int[] sortArrayByParityII(int[] A) { List<Integer> oddList = new ArrayList<>(); List<I…
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…
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…
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…
这是悦乐书的第354次更新,第379篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第216题(顺位题号是922).给定非负整数的数组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.leng…