Skip to content

Commit d191cd5

Browse files
Merge pull request PawanJaiswal08#16 from AmanSingh81757/master
Create 2149. rearrange array elements by sign.cpp
2 parents 5dc2d2f + e3d9162 commit d191cd5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
vector<int> rearrangeArray(vector<int>& nums) {
4+
int x= nums.size();
5+
vector<int> a(x);
6+
int i=0,j=1;
7+
for(int k=0;k<x;k++){
8+
if(nums[k]>0){
9+
a[i]=nums[k];
10+
i+=2;
11+
}
12+
else{
13+
a[j]=nums[k];
14+
j+=2;
15+
}
16+
}
17+
return a;
18+
}
19+
};

0 commit comments

Comments
 (0)