当前位置:网站首页>[leetcode 324] swing sorting II thinking + sorting
[leetcode 324] swing sorting II thinking + sorting
2022-07-01 14:41:00 【PushyTao】
Topic link 
Given some numbers , Rearrange them to meet :
< > < > < … Sequence of relationships
Ideas :
Sort from small to large , Then put the odd digits , Place from left to right, from large to small ; Turn even bits from left to right , Place from large to small , We can get the satisfied result sequence
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;
}
};
边栏推荐
- 【R语言数据科学】:机器学习常见评估指标
- Oracle-数据库对象的使用
- Play with mongodb - build a mongodb cluster
- Research Report on the development trend and competitive strategy of the global camera filter bracket industry
- Why did you win the first Taosi culture award of 20000 RMB if you are neither a top R & D expert nor a sales Daniel?
- 2022-2-15 learning the imitation Niuke project - post in Section 2
- 使用net core 6 c# 的 NPOI 包,讀取excel..xlsx單元格內的圖片,並存儲到指定服務器
- [Verilog quick start of Niuke question series] ~ use functions to realize data size conversion
- 券商万1免5证券开户是合理安全的吗,怎么讲
- Basic knowledge of C language
猜你喜欢

2022-2-15 learning xiangniuke project - Section 1 filtering sensitive words

深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障

C learning notes (5) class and inheritance

sqlilabs less-11~12

2022 PMP project management examination agile knowledge points (6)

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

如何看待国企纷纷卸载微软Office改用金山WPS?

sqlilabs less9

Vnctf2022 open web gocalc0

phpcms实现订单直接支付宝支付功能
随机推荐
【15. 区间合并】
[getting started with Django] 13 page Association MySQL "multi" field table (check)
Details of appium key knowledge
券商万1免5证券开户是合理安全的吗,怎么讲
【牛客网刷题系列 之 Verilog快速入门】~ 多功能数据处理器、求两个数的差值、使用generate…for语句简化代码、使用子模块实现三输入数的大小比较
[Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
JVM performance tuning and practical basic theory part II
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
Open source internship experience sharing: openeuler software package reinforcement test
Phpcms realizes the direct Alipay payment function of orders
How can we protect our passwords?
Buuctf reinforcement question ezsql
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
手把手带你入门 API 开发
Don't want to knock the code? Here comes the chance
[dynamic programming] p1004 grid access (four-dimensional DP template question)
既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?
Research Report on development trend and competitive strategy of global 4-aminodiphenylamine industry
What problems should be considered for outdoor LED display?