Skip to content

Commit 45880a9

Browse files
committedOct 3, 2024
1470 shuffle the array c++
1 parent 9800d75 commit 45880a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎cpp/1470-shuffle-the-array.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> shuffle(vector<int>& nums, int n) {
4+
int lp = 0;
5+
int rp = n;
6+
int p = 0;
7+
vector<int> shuffled(2*n);
8+
9+
while (p < 2 * n) {
10+
shuffled[p++] = nums[lp++];
11+
shuffled[p++] = nums[rp++];
12+
}
13+
return shuffled;
14+
}
15+
};

0 commit comments

Comments
 (0)
Please sign in to comment.