Created
August 21, 2020 12:17
-
-
Save RP-3/a2a1ca41ce3015785268286b6ddf980c to your computer and use it in GitHub Desktop.
Leetcode sort by parity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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