Skip to content

Commit 552cabe

Browse files
authored
Create minimum-add-to-make-parentheses-valid-ii.py
1 parent 0838f07 commit 552cabe

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def sortArrayByParityII(self, A):
6+
"""
7+
:type A: List[int]
8+
:rtype: List[int]
9+
"""
10+
j = 1
11+
for i in xrange(0, len(A), 2):
12+
if A[i] % 2:
13+
while A[j] % 2:
14+
j += 2
15+
A[i], A[j] = A[j], A[i]
16+
return A

0 commit comments

Comments
 (0)