当前位置:网站首页>[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;
}
};
边栏推荐
- SQLAchemy 常用操作
- About the use of HTTP cache validation last modified and Etag
- "National defense seven sons" funding soared, with Tsinghua reaching 36.2 billion yuan, ranking second with 10.1 billion yuan. The 2022 budget of national colleges and universities was made public
- Basic operation of queue (implemented in C language)
- 既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?
- Opencv interpolation mode
- sqlilabs less9
- 【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
- 2022-2-15 learning xiangniuke project - Section 4 business management
- Research Report on development trend and competitive strategy of global vibration polishing machine industry
猜你喜欢

111. Minimum depth of binary tree

Fundamentals of C language

Word2vec yyds dry goods inventory
![[R language data science]: common evaluation indicators of machine learning](/img/c8/dbfb041fa72799fae1892fe8ac0050.png)
[R language data science]: common evaluation indicators of machine learning

Après avoir été licencié pendant trois mois, l'entrevue s'est effondrée et l'état d'esprit a commencé à s'effondrer.

既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?

一波三折,终于找到src漏洞挖掘的方法了【建议收藏】

微服务开发步骤(nacos)

Microservice development steps (Nacos)

2022-2-15 learning xiangniuke project - Section 1 filtering sensitive words
随机推荐
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
Develop small programs and official account from zero [phase III]
Today, with the popularity of micro services, how does service mesh exist?
互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
Error-tf.function-decorated function tried to create variables on non-first call
Basic concepts of programming
NPDP产品经理国际认证报名有什么要求?
手把手带你入门 API 开发
适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
Use of Oracle database objects
既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?
Research Report on the development trend and competitive strategy of the global high temperature label industry
对于编程思想和能力有重大提升的书有哪些?
About the use of HTTP cache validation last modified and Etag
Opencv interpolation mode
JVM performance tuning and practical basic theory part II
C 语言进阶
【14. 区间和(离散化)】
Provincial election + noi Part VIII fraction theory
Texstudio tutorial