3289: The-Two-Sneaky-Numbers-of-Digitville
Easy


table of contents

Just run a simple hashmap to check for duplicates.

code

class Solution {
public:
    vector<int> getSneakyNumbers(vector<int>& nums) {
        vector<int> ans;
        unordered_set<int> seen;
        for (int& num : nums) {
            if (!seen.count(num)) {
                seen.insert(num);
            } else {
                ans.push_back(num);
            }
        }
        return ans;
    }
};

complexity

learnings

time taken