Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created August 21, 2020 12:17
Show Gist options
  • Save RP-3/a2a1ca41ce3015785268286b6ddf980c to your computer and use it in GitHub Desktop.
Save RP-3/a2a1ca41ce3015785268286b6ddf980c to your computer and use it in GitHub Desktop.
Leetcode sort by parity
/**
* @param {number[]} A
* @return {number[]}
*/
var sortArrayByParity = function(A) {
let [l,r] = [0,A.length-1]
while(l<r){
if(A[l] %2){
[A[l],A[r]] = [A[r],A[l]]
r--
} else {
l++
}
}
return A;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment