leetcode

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

2161.cpp (558B)


      1 class Solution {
      2   public:
      3     vector<int> pivotArray(vector<int> &nums, int pivot) {
      4         vector<int> tmp;
      5         tmp.reserve(nums.size());
      6         int count = 0, idx = 0;
      7         for (int num : nums) {
      8             if (num == pivot)
      9                 count++;
     10             else if (num > pivot)
     11                 tmp.push_back(num);
     12             else
     13                 nums[idx++] = num;
     14         }
     15 
     16         for (int i = 0; i < count; i++)
     17             nums[idx++] = pivot;
     18         for (int num : tmp)
     19             nums[idx++] = num;
     20         return nums;
     21     }
     22 };