当前位置:网站首页>[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;
}
};
边栏推荐
- Research Report on the development trend and competitive strategy of the global aviation leasing service industry
- JVM performance tuning and practical basic theory part II
- Provincial election + noi Part IX game theory
- NPDP能给产品经理带来什么价值?你都知道了吗?
- Research Report on the development trend and competitive strategy of the global ultrasonic scalpel system industry
- Play with mongodb - build a mongodb cluster
- C 语言进阶
- 【R语言数据科学】:机器学习常见评估指标
- Go integrates logrus to realize log printing
- When the main process architecture game, to prevent calls everywhere to reduce coupling, how to open the interface to others to call?
猜你喜欢
随机推荐
Build your own website (14)
原来程序员搞私活这么赚钱?真的太香了
How can we protect our passwords?
Research Report on the development trend and competitive strategy of the global aviation leasing service industry
Research Report on the development trend and competitive strategy of the global facial wrinkle removal and beauty instrument industry
Blog recommendation | in depth study of message segmentation in pulsar
C 语言基础
C#学习笔记(5)类和继承
Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables
Sorting learning sorting
百度上找的期货公司安全吗?期货公司怎么确定正规
【修复版】仿我爱看电影网站模板/海洋CMS影视系统模板
Texstudio tutorial
2022-2-15 learning xiangniuke project - Section 4 business management
光环效应——谁说头上有光的就算英雄
Websocket (simple experience version)
MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
Realize queue with stack and stack with queue (C language \leetcode\u 232+225)
Microservice development steps (Nacos)









