isaacpei / algorithm-interview

Weekly algorithm questions for interview
18 stars 0 forks source link

Q004_palayutm_solution #32

Open palayutm opened 6 years ago

palayutm commented 6 years ago

Question_ID: Q004

Language: c++

Time Cost: 40-mins

Time Complexity: O(n)

Solution

My Code

void reorder(vector<int>& a) {
  for (int i = 1; i < a.size(); i++) {
    if ((i & 1) ^ (a[i] >= a[i - 1])) {
      swap(a[i], a[i - 1]);
    }
  }
}

Other

ryanorz commented 6 years ago

这波精简的我服

isaacpei commented 6 years ago

好好好你们短你们短