[javascript] O(n)
\n/**\n * @param {number[]} A\n * @return {number[]}\n */\nvar sortArrayByParityII = function(A) {\n    let result = new Array(A.length);\n    \n    for(let i =
```\n/**\n * @param {number[]} A\n * @return {number[]}\n */\nvar sortArrayByParityII = function(A) {\n    let result = new Array(A.length);\n    \n    for(let i = 0, even = 0, odd = 1; i < A.length; i ++) {\n        if(A[i] % 2 === 0) {\n            result[even] = A[i];\n            even += 2;\n        } else {\n            result[odd] = A[i];\n            odd += 2;\n        }\n    }\n    return result;\n};\n```
['JavaScript']