../ Competitive Programming
-rw-r--r--aguang687 B1 min read

Leet Code Daily 2024-06-11 - Relative Sort Array

Code

c++
class Solution {
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
        map<int, int> freq;
        for (const auto& x : arr1) {
            freq[x]++;
        }
        vector<int> ans;
        for (const auto& x : arr2) {
            while (freq[x]-- > 0) {
                ans.push_back(x);
            }
        }
        for (const auto& p : freq) {
            const int x = p.first;
            while (freq[x]-- > 0) {
                ans.push_back(x);
            }
        }
        return ans;
    }
};

COMMAND INTERFACE

↑ ↓ navigate · Enter execute · Esc exit · try “whoami”

Loading filesystem…

:help aguang.xyz

A personal website disguised as an operating system.

Ctrl / Cmd + K
Command palette + full-text search
Tab / Shift + Tab
Move between links and controls
Enter
Open a focused link or search result
↑ / ↓ in search
Navigate search results
In a directory filter
Enter/Done or ↓ focuses a result; Esc clears the filter
Esc
Clear a search or close a window