当前位置:网站首页>[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;
}
};
边栏推荐
- Provincial election + noi Part XI others
- 如何看待国企纷纷卸载微软Office改用金山WPS?
- Force deduction solution summary 241- design priority for operation expression
- Word2vec yyds dry goods inventory
- [R language data science]: common evaluation indicators of machine learning
- [15. Interval consolidation]
- Research Report on the development trend and competitive strategy of the global electromagnetic flowmeter industry
- Today, with the popularity of micro services, how does service mesh exist?
- 对于编程思想和能力有重大提升的书有哪些?
- Provincial election + noi Part 10 probability statistics and polynomials
猜你喜欢
户外LED显示屏应该考虑哪些问题?
Minimum spanning tree and bipartite graph in graph theory (acwing template)
sqlilabs less10
Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine
Admire, Ali female program undercover more than 500 black production groups
2022-2-15 learning the imitation Niuke project - Section 3 post details
Don't want to knock the code? Here comes the chance
JVM performance tuning and practical basic theory part II
博文推荐 | 深入研究 Pulsar 中的消息分块
Semiconductor foundation of binary realization principle
随机推荐
数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
Word2vec yyds dry goods inventory
sqlilabs less9
Provincial election + noi Part 10 probability statistics and polynomials
Salesforce, Johns Hopkins, Columbia | progen2: exploring the boundaries of protein language models
TDengine 连接器上线 Google Data Studio 应用商店
sqlilabs less-8
Research Report on the development trend and competitive strategy of the global diamond suspension industry
C 语言进阶
Problem note - Oracle 11g uninstall
Semiconductor foundation of binary realization principle
[14. Interval sum (discretization)]
How can we protect our passwords?
[R language data science]: common evaluation indicators of machine learning
一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
Details of appium key knowledge
【14. 区间和(离散化)】
户外LED显示屏应该考虑哪些问题?
Pat 1121 damn single (25 points) set
Phpcms realizes the direct Alipay payment function of orders