Skip to content

Commit dc515ed

Browse files
committed
Add 922-SortArrayByParityII.cpp
1 parent 10ea9c3 commit dc515ed

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
vector<int> sortArrayByParityII(vector<int>& nums) {
4+
std::vector<int> res(nums.size(), 0);
5+
int a(0), b(1);
6+
for(int p = 0; p < nums.size(); p++){
7+
if(nums[p] % 2){res[b] = nums[p]; b += 2;}
8+
else{res[a] = nums[p]; a += 2;}
9+
}
10+
11+
return res;
12+
}
13+
};

0 commit comments

Comments
 (0)