Skip to content

Commit 1ef9dce

Browse files
committed
Runtime: 7 ms (Top 67.86%) | Memory: 16.80 MB (Top 16.67%)
1 parent 2c9a125 commit 1ef9dce

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1+
// Runtime: 7 ms (Top 67.86%) | Memory: 16.80 MB (Top 16.67%)
2+
13
class Solution {
24
public:
3-
vector<int> sortArrayByParity(vector<int>& nums)
4-
{
5-
vector<int> v;
6-
vector<int> odd;
7-
if(nums.size()==1)
8-
{
9-
return nums;
10-
}
11-
for(auto it : nums)
12-
{
13-
if(it%2==0)
14-
{
15-
v.push_back(it);
16-
}
17-
else
18-
{
19-
odd.push_back(it);
5+
std::vector<int> sortArrayByParity(std::vector<int>& nums) {
6+
std::vector<int> result;
7+
for (int i : nums) {
8+
if (i % 2 == 0) {
9+
result.push_back(i);
2010
}
21-
2211
}
23-
24-
for(auto i : odd)
25-
{
26-
v.push_back(i);
12+
for (int j : nums) {
13+
if (j % 2 != 0) {
14+
result.push_back(j);
15+
}
2716
}
28-
return v;
17+
return result;
2918
}
30-
};
19+
};
20+

0 commit comments

Comments
 (0)