leetcode

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

3264.cpp (638B)


      1 class Solution {
      2   public:
      3     vector<int> getFinalState(vector<int> &nums, int k, int multiplier) {
      4         using type_t = pair<int, int>;
      5         priority_queue<type_t, vector<type_t>, greater<>> pq;
      6         const int n = size(nums);
      7 
      8         for (int i = 0; i < n; i++) {
      9             pq.emplace(nums[i], i);
     10         }
     11 
     12         while (k--) {
     13             const auto [val, idx] = pq.top();
     14             pq.pop();
     15             pq.emplace(val * multiplier, idx);
     16         }
     17 
     18         while (!pq.empty()) {
     19             const auto [val, idx] = pq.top();
     20             pq.pop();
     21             nums[idx] = val;
     22         }
     23 
     24         return nums;
     25     }
     26 };