1. What I learned
a. LIST.insert(INDEX, e)
To insert an element in a list where you want, write as follows.
LIST = [1,2,3]
LIST.insert(0,4)
print LIST
#It will print '4,1,2,3'
2. How I sloved
I added two lists, one with even numbers as element and the other with odd numbers.
3. Code
class Solution:
def sortArrayByParity(self, A: List[int]) -> List[int]:
return [e for e in A if e%2==0] + [e for e in A if e%2==1]
4. Result
Runtime : 64 ms(99.93%), Memory usage : 14.6 MB(5.67%)
(Runtime can be different by a system even if it is a same code.)