思路:我特喵的直接暴力解法
/** * @param {number[]} nums * @return {number[]} */ var sortArrayByParityII = function(nums) { let arr = [] let arr_ou = [] let arr_ji = [] nums.forEach(data => { data % 2 === 0 ? arr_ou.push(data) : arr_ji.push(data) }) for (let i = 0; i<arr_ji.length ;i++) { arr[i * 2] = arr_ou[i] arr[i * 2 + 1] = arr_ji[i] } return arr };
评论区