当前位置:网站首页>[leetcode 324] 摆动排序 II 思维+排序
[leetcode 324] 摆动排序 II 思维+排序
2022-07-01 14:37:00 【PushyTao】
题目链接
给定一些数,要把他们重新排列成满足:
< > < > < …关系的序列
思路:
从小到大排序,然后将奇数位,从左向右从大到小放置;将偶数位从左向右,从大到小放置,即可得到满足的结果序列
Code:
class Solution {
public:
void wiggleSort(vector<int>& nums) {
sort(nums.begin(), nums.end());
int n = nums.size();
vector<int> v(n);
int r = n - 1,l = 1;
for(;l < n;l += 2) {
v[l] = nums[r];
r --;
}
for(l = 0;l < n;l += 2) {
v[l] = nums[r];
r --;
}
nums = v;
}
};
边栏推荐
- Halo effect - who says that those with light on their heads are heroes
- [零基础学IoT Pwn] 复现Netgear WNAP320 RCE
- SWT / anr problem - how to capture performance trace
- 【R语言数据科学】:机器学习常见评估指标
- 数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
- sqlilabs less-11~12
- Develop small programs and official account from zero [phase III]
- Basis of target detection (NMS)
- Realize queue with stack and stack with queue (C language \leetcode\u 232+225)
- Sqlachemy common operations
猜你喜欢

643. Maximum average number of subarrays I

241. Design priorities for operational expressions

MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发

sqlilabs less10

Leetcode (69) -- square root of X

Blog recommendation | in depth study of message segmentation in pulsar

Open source internship experience sharing: openeuler software package reinforcement test

Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server

Play with mongodb - build a mongodb cluster

【14. 区间和(离散化)】
随机推荐
使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
生成随机数(4位、6位)
Research Report on development trend and competitive strategy of global 4-aminodiphenylamine industry
So programmers make so much money doing private work? It's really delicious
被裁三個月,面試到處碰壁,心態已經開始崩了
sqlilabs less13
[14. Interval sum (discretization)]
【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
Yyds dry goods inventory hcie security day13: firewall dual machine hot standby experiment (I) firewall direct deployment, uplink and downlink connection switches
Details of appium key knowledge
2022-2-15 learning the imitation Niuke project - Section 3 post details
[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion
Guess lantern riddles, not programmers still can't understand?
Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine
Texstudio tutorial
Provincial election + noi Part VIII fraction theory
Research Report on the development trend and competitive strategy of the global commercial glassware industry
Buuctf reinforcement question ezsql
111. Minimum depth of binary tree