[Javascript] InPlace and using space 90% faster
Please upvote if you find this solution useful\n\nIn place\n\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParityII = function(num
**Please upvote if you find this solution useful**\n\n**In place**\n```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParityII = function(nums) {\n  let even = 0;\n    let odd = nums.length - 1;\n    while(even < nums.length && odd >= 0){\n        \n        if(nums[even] % 2==0 && nums[odd] % 2 !== 0){\n            even = even + 2;\n            odd = odd - 2\n        }else if(nums[even] % 2 !== 0 && nums[odd] % 2 == 0){\n            [ nums[even] , nums[odd] ] = [ nums[odd] , nums[even] ]\n        }else if(nums[even] % 2 ==0 ){\n            even = even+2;\n        }else{\n            odd = odd - 2;\n        }\n    }\n    return nums\n};\n```\n\n\n**Using space**\n```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParityII = function(nums) {\n    var arr = new Array(nums.length);\n    var even  =0;\n    var odd = 1;\n    for(let i=0; i<nums.length; i++){\n        if(nums[i] % 2 === 0){\n            arr[even] = nums[i];\n            even +=2;\n        }else{\n            arr[odd] = nums[i]\n            odd +=2\n        }\n    }\n    return arr\n    \n};\n```
['Two Pointers', 'JavaScript']