重新排列数组 - C++力扣1470题
题目链接:https://leetcode.com/problems/shuffle-the-array/
解题思路
老实说,这题一看到就让人丧失了对其进行优化的心思了,随便写写都能过,完完全全入门级的题目,不多做解释了,直接上代码。
完整代码:
class Solution {
public:
vector<int> shuffle(vector<int>& nums, int n) {
int v1 = 0, v2 = (nums.size() / 2);
vector<int> ans;
while(v2 < nums.size()) {
ans.push_back(nums[v1]);
ans.push_back(nums[v2]);
v1++;
v2++;
}
return ans;
}
};
/www/wwwroot/www.yuisblog.com/usr/themes/dinner/post.php on line 86
" itemprop="url" class="inline-block mb-3 shadow mx-0.5 px-2 py-1 text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-700 rounded-lg">#C++编程 /www/wwwroot/www.yuisblog.com/usr/themes/dinner/post.php on line 86
" itemprop="url" class="inline-block mb-3 shadow mx-0.5 px-2 py-1 text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-700 rounded-lg">#力扣打卡
" itemprop="url" class="inline-block mb-3 shadow mx-0.5 px-2 py-1 text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-700 rounded-lg">#C++编程 /www/wwwroot/www.yuisblog.com/usr/themes/dinner/post.php on line 86
" itemprop="url" class="inline-block mb-3 shadow mx-0.5 px-2 py-1 text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-700 rounded-lg">#力扣打卡
版权属于:我是苏云曦吖
本文链接:https://yuisblog.com/archives/230/
本站未注明转载的文章均为原创,并采用
CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!