Average O(n log n) Time, O(1) Space C++ Solution


#1
vector Solution::wave(vector &A) {
    sort(A.begin(),A.end());
    for(int i=0;i<A.size();i+=2)
        if(i+1<A.size())
            swap(A[i],A[i+1]);
    return A;
}