[leetcode] 905. Sort Array By Parity [easy]】的更多相关文章

原题链接 很水的一道题,就是数组内部交换. 水题就想着减少复杂度嘛,于是学到一种交换写法. class Solution { public: vector<int> sortArrayByParity(vector<int> &A) { int i = 0, j = A.size()-1; while (i < j) { if (A[i] & 0x01) { A[i] ^= A[j]; A[j] ^= A[i]; A[i] ^= A[j]; --j; } el…
905. Sort Array By Parity 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. Example 1: Input: [3,…
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. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] T…
题目要求 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. 题目分析及思路 题目给出一个含有非负整数的数组A,要求返回一个数组,前面的元素都是A…
题目 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. Example 1: Input: [3,1,2,4] Output: [2,4,3,1…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: SortArrayByParity * @Author: xiaof * @Description: 905. Sort Array By Parity * Given an array A of non-negative integers, return an array…
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list,一个放偶数,一个放奇数,最后将两个list合并,转化为数组返回 Java实现: public int[] sortArrayByParity(int[] A) { List<Integer> evenList = new ArrayList<>(); List<Integer&g…
problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByParity(vector<int>& A) { vector<int> even, odd; for(auto a:A) { ==) even.push_back(a); else odd.push_back(a); } even.insert(even.end(), odd.…
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…
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…