2 wyr2446541820 WYR2446541820 于 2016.02.29 09:42 提问

Wiggle Sort II,最后将以排好的数组合在一起 10C

leetcode的一道题,Wiggle Sort II,里面我用快速排序找到了中位median,然后就要将这些数组合在一起,就是到这一步遇到了问题,比如出现【4,5,5,6】就会出错。
请大神指点

1个回答

devmiao
devmiao   Ds   Rxr 2016.02.29 23:07
WYR2446541820
WYR2446541820 不懂这个int transformInd(int i, int len) { if(i < (len >> 1)) return i*2+1; else return (i - (len>>1))*2; }
2 年多之前 回复
WYR2446541820
WYR2446541820 不懂这个int transformInd(int i, int len) { if(i < (len >> 1)) return i*2+1; else return (i - (len>>1))*2; }
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
[leetcode] 324. Wiggle Sort II 解题报告
题目链接:https://leetcode.com/problems/wiggle-sort-ii/ Given an unsorted array nums, reorder it such that nums[0] nums[2] . Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is
324. Wiggle Sort II 摆动排序
Given an unsorted array nums, reorder it such that nums[0] nums[2] . 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
[LeetCode 324] Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] nums[2] . 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
LeetCode 324. Wiggle Sort II(摇摆排序)
原题网址:https://leetcode.com/problems/wiggle-sort-ii/ Given an unsorted array nums, reorder it such that nums[0] nums[2] . Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is
LeetCode Wiggle Sort II
Description: Given an unsorted array nums, reorder it such that nums[0] nums[2] . Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].  (2) Given num
[leetcode] - 324. Wiggle Sort II
题意大致为将给定数组中的元素按形如nums[0] < nums[1] > nums[2] < nums[3]….这种样子排列,顺序没要求。这道题O(1)时间复杂度和空间复杂度的最优解暂时没想出来,用蠢办法解决。方案为先复制当前数组,将复制的数组排序,然后以中位数为界将数组分为两部分,small part和large part。交替填入原始数组即可,这样做的原因是可以避免有值相同的数组挨在一起,以符合
[leetcode] 280. Wiggle Sort 解题报告
题目链接: https://leetcode.com/problems/wiggle-sort/ Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] . For example, given nums = [3, 5, 2, 1, 6, 4], one possible an
LeetCode -- Wiggle Sort II
LeetCode -- Wiggle Sort II
[Leetcode] 324. Wiggle Sort II 解题报告
题目: Given an unsorted array nums, reorder it such that nums[0] nums[2] . 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
leetcode-Wiggle Sort II-324
对数组进行摆动排序 排序、分成两半、依次从两段的后端往前取数 O(nlgn)  空间:O(n) class Solution { public: void wiggleSort(vector& nums) { sort(nums.begin(), nums.end()); int mid=(nums.size()+1)/2; int s=