Skip to content

Commit 72ecfd5

Browse files
authored
Added solution for shuffle the array. (#385)
1 parent 5ba9c60 commit 72ecfd5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

C++/shuffle-the-array.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
vector<int> shuffle(vector<int>& nums, int n) {
4+
for(int i=0;i<n;i++){
5+
nums[i]=nums[i]<<10;
6+
nums[i]=nums[i]|nums[i+n];
7+
}
8+
int ptr=2*n-1;
9+
10+
for(int i=n-1;i>=0;i--){
11+
int y =nums[i]&((1<<10)-1);
12+
int x =nums[i]>>10;
13+
nums[ptr]=y;
14+
nums[ptr-1]=x;
15+
ptr-=2;
16+
}
17+
return nums;
18+
}
19+
};
20+
auto init=[](){
21+
ios::sync_with_stdio(false);
22+
cin.tie(nullptr);
23+
cout.tie(nullptr);
24+
return 'c';
25+
}();

0 commit comments

Comments
 (0)