当前位置:网站首页>[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 CCTV robot industry
- [零基础学IoT Pwn] 复现Netgear WNAP320 RCE
- 关于软件测试的一些思考
- TDengine 连接器上线 Google Data Studio 应用商店
- In depth cooperation | Taosi data cooperates with changhongjia Huawei customers in China to provide tdengine with powerful enterprise level products and perfect service guarantee
- 生成随机数(4位、6位)
- Tdengine connector goes online Google Data Studio app store
- One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
- En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
- Research Report on the development trend and competitive strategy of the global chemical glassware industry
猜你喜欢

What problems should be considered for outdoor LED display?

Realize queue with stack and stack with queue (C language \leetcode\u 232+225)

问题随记 —— Oracle 11g 卸载

In depth cooperation | Taosi data cooperates with changhongjia Huawei customers in China to provide tdengine with powerful enterprise level products and perfect service guarantee

2022-2-15 learning the imitation Niuke project - Section 3 post details
![[dynamic programming] interval dp:p1005 matrix retrieval](/img/c9/2091f51b905d2c0ebc978dab3d34d3.jpg)
[dynamic programming] interval dp:p1005 matrix retrieval

Leetcode (69) -- square root of X

Opencv interpolation mode
![[14. Interval sum (discretization)]](/img/e5/8b29aca7068a6385e8ce90c2742c37.png)
[14. Interval sum (discretization)]

sqlilabs less-8
随机推荐
用对场景,事半功倍!TDengine 的窗口查询功能及使用场景全介绍
MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
Provincial election + noi Part VIII fraction theory
643. Maximum average number of subarrays I
Buuctf reinforcement question ezsql
Research Report on development trend and competitive strategy of global 4-aminodiphenylamine industry
30 Devops interview questions and answers
【14. 区间和(离散化)】
So programmers make so much money doing private work? It's really delicious
Build your own website (14)
深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障
Provincial election + noi Part IX game theory
2022 PMP project management examination agile knowledge points (6)
百度上找的期货公司安全吗?期货公司怎么确定正规
JVM performance tuning and practical basic theory part II
Opencv interpolation mode
MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
户外LED显示屏应该考虑哪些问题?
[stage life summary] I gave up the postgraduate entrance examination and participated in the work. I have successfully graduated and just received my graduation certificate yesterday
Yyds dry goods inventory hcie security day13: firewall dual machine hot standby experiment (I) firewall direct deployment, uplink and downlink connection switches