Created
July 15, 2019 22:59
-
-
Save piyushdec/6f205b236a4c74ad404d43b2dc4c8659 to your computer and use it in GitHub Desktop.
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
| func sortArrayByParityII(_ A: [Int]) -> [Int] { | |
| var even: [Int] = [] | |
| var odd: [Int] = [] | |
| var result: [Int] = [] | |
| for element in A { | |
| if(element % 2 == 0) { | |
| even.append(element) | |
| } else { | |
| odd.append(element) | |
| } | |
| } | |
| for index in 0 ..< even.count { | |
| result.append(even[index]) | |
| result.append(odd[index]) | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment