标签:
One-pass Greedy solution. So beautiful.
class Solution { public: void wiggleSort(vector<int>& nums) { for(int i = 1; i < nums.size(); i ++) { if (i % 2) { if(nums[i - 1] > nums[i]) swap(nums[i - 1], nums[i]); } else { if(nums[i - 1] < nums[i]) swap(nums[i - 1], nums[i]); } } } };
标签:
原文地址:http://www.cnblogs.com/tonix/p/4799804.html