博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
324. Wiggle Sort II
阅读量:4499 次
发布时间:2019-06-08

本文共 813 字,大约阅读时间需要 2 分钟。

Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....

Example:

(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]
(2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].

Note:

You may assume all input has valid answer.

Follow Up:

Can you do it in O(n) time and/or in-place with O(1) extra space?

含义:给定一个没有排序的数组,重排以后达到 nums[0] < nums[1] > nums[2] < nums[3]....这种效果

1     public void wiggleSort(int[] nums) { 2         //        先给数组排序,然后找到数组的中间的数,相当于把有序数组从中间分成两部分,然后从前半段的末尾取一个,在从后半的末尾去一个,以此类推直至都取完 3         int[] temp = (int[])nums.clone(); 4         Arrays.sort(temp); 5         int n = nums.length,k=(1+n)/2,j=n; 6         boolean flag = true; 7         for (int i=0;i

 

转载于:https://www.cnblogs.com/wzj4858/p/7731903.html

你可能感兴趣的文章
笔记22 基础知识
查看>>
Game02 最新版本2.0.0
查看>>
std::set 中内部元素有序条件删除的理解
查看>>
初步认识Less
查看>>
matlab find函数用法
查看>>
Django 用户登陆访问限制 @login_required
查看>>
给没有id主键的表添加id,并设置为not null 然后填充自增id
查看>>
python之函数用法file()
查看>>
order by
查看>>
Web应用程序开发知识点回顾
查看>>
NetMQ介绍
查看>>
CentOS 6.0 系统 LAMP(Apache+MySQL+PHP) 安装步骤
查看>>
oracle 内连接 左外连接 右外连接的用法,(+)符号用法
查看>>
深入理解javascript闭包
查看>>
敏捷练习(1)评估我的生活方向盘
查看>>
web版微信自动发消息(实现微信个人号机器人)
查看>>
【C/C++】产生随机数
查看>>
dp_c_区间dp_g
查看>>
C#Dictionary键值对取值用法
查看>>
关于动态绑定时遇到的问题:
查看>>