324. Wiggle Sort II

sort
find mid point 
take one from the end of the two lists one by one 
class Solution(object):
    def wiggleSort(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        temp=nums[:]
        temp.sort()
        small,large=(len(nums)-1)/2,len(nums)-1
        for i in xrange(len(nums)):
            if i%2==0:
                nums[i]=temp[small]
                small-=1
            else:
                nums[i]=temp[large]
                large-=1
O(n)+O(1) after median --- Virtual Indexing

https://discuss.leetcode.com/topic/32929/o-n-o-1-after-median-virtual-indexing

read and come back to it 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Given an unsorted array nums, reorder it such that nums[0...
    Jeanz阅读 497评论 0 0
  • 题目来源这道题的解法,我看了老半天,然后还是有点懵逼,先找中位数,然后比中位数大的和比中位数小的划分为两块,交换位...
    我叫胆小我喜欢小心阅读 366评论 0 0
  • 描述 给定一个有n个对象(包括k种不同的颜色,并按照1到k进行编号)的数组,将对象进行分类使相同颜色的对象相邻,并...
    6默默Welsh阅读 254评论 0 0
  • Given an unsorted array nums, reorder it in-place such th...
    六尺帐篷阅读 996评论 0 1
  • 前言 随着移动互联网的飞速发展,移动端产品满天飞,深入各行各业,移动端安全已经变得跟PC端安全同等重要地位。但由于...
    海波笔记阅读 14,066评论 0 52