forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.py
34 lines (25 loc) · 730 Bytes
/
12.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding:utf-8 -*-
class Solution:
def reOrderArray(self, array):
# write code here
jiCount = 0
ouCount = 0
for itemArray in array:
if itemArray % 2 == 0:
ouCount += 1
else:
jiCount += 1
jiIndex = 0
ouIndex = jiCount
arraySize = len(array)
newArray = [0] * arraySize
for i in range(arraySize):
if array[i] % 2 == 1:
newArray[jiIndex] = array[i]
jiIndex += 1
else:
newArray[ouIndex] = array[i]
ouIndex += 1
return newArray
solution = Solution()
print solution.reOrderArray([1, 2, 3, 4, 5])