Skip to content

Instantly share code, notes, and snippets.

@piyushdec
Created July 15, 2019 22:59
Show Gist options
  • Select an option

  • Save piyushdec/6f205b236a4c74ad404d43b2dc4c8659 to your computer and use it in GitHub Desktop.

Select an option

Save piyushdec/6f205b236a4c74ad404d43b2dc4c8659 to your computer and use it in GitHub Desktop.
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