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 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Given an unsorted array nums, reorder it such that nums[0...
    Jeanz閱讀 544評(píng)論 0 0
  • 題目來(lái)源這道題的解法,我看了老半天,然后還是有點(diǎn)懵逼,先找中位數(shù),然后比中位數(shù)大的和比中位數(shù)小的劃分為兩塊,交換位...
    我叫膽小我喜歡小心閱讀 411評(píng)論 0 0
  • 描述 給定一個(gè)有n個(gè)對(duì)象(包括k種不同的顏色,并按照1到k進(jìn)行編號(hào))的數(shù)組,將對(duì)象進(jìn)行分類使相同顏色的對(duì)象相鄰,并...
    6默默Welsh閱讀 306評(píng)論 0 0
  • Given an unsorted array nums, reorder it in-place such th...
    六尺帳篷閱讀 1,030評(píng)論 0 1
  • 前言 隨著移動(dòng)互聯(lián)網(wǎng)的飛速發(fā)展,移動(dòng)端產(chǎn)品滿天飛,深入各行各業(yè),移動(dòng)端安全已經(jīng)變得跟PC端安全同等重要地位。但由于...
    海波筆記閱讀 14,310評(píng)論 0 52

友情鏈接更多精彩內(nèi)容