leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2149.cpp (309B)


      1 // 2149. Rearrange Array Elements by Sign
      2 class Solution {
      3   public:
      4     vector<int> rearrangeArray(const vector<int> &nums) {
      5         vector<int> res(nums.size());
      6         int i = -2, j = -1;
      7         for (int num : nums)
      8             (num > 0 ? res[i += 2] : res[j += 2]) = num;
      9 
     10         return res;
     11     }
     12 };