Why this got a Runtime Error? No problem in my local machine


  • 0
    W

    The idea is quite simple, just place the larger half to the positions where indexes are even.

    class Solution {
    public:
        void wiggleSort(vector<int>& nums) {
            vector<int> vec(nums);
            sort(vec.begin(), vec.end(), greater<int>());
            int j = 0;
            for(int i = 1; i < nums.size(); i += 2){
                nums[i] = vec[j++];
            }
            for(int i = 0; i < nums.size(); i += 2){
                nums[i] = vec[j++];
            }
            
        }
    };

  • 0

    Could you please try submitting again? I have made some changes to the test case.


  • 0
    W

    No problem. This time it accepted:D


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.