[Leet Code] Sort Array By Parity II

Input: [4,2,5,7]
Output: [4,5,2,7]
Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
class Solution(object):
def sortArrayByParityII(self, A):
:type A: List[int]
:rtype: List[int]
answers = [0] * len(A)
even = 0
odd = 1
for i in A:
if i % 2 == 0:
answers[even] = i
even += 2
answers[odd] = i
odd += 2
return answers




Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Python Data Structure- Part 2

[Guide] C-Lightning backup guide

Deploy Stripe while keeping your core product team focused.

Developing an Infrastructure using Terraform with the help of EFS

A Simple Git Workflow

How we are minimizing no-show pop up vendors

ARM Servers on AWS: How to Save up to 30%

Standardize display of checkboxes in APEX

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

Algorithms: Recursion/Backtracking, Combinations

Add Two Number 📯

LeetCode: Palindrome Number

Sliding Window #1: Finding the maximum sum of k consecutive elements in an array