a few solutions
Use a map m to count each value x of the input array A.\n\n---\n\nKotlin\n\nclass Solution {\n    fun findLonely(A: IntArray): List<Int> {\n        var m = muta
Use a map `m` to count each value `x` of the input array `A`.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun findLonely(A: IntArray): List<Int> {\n        var m = mutableMapOf<Int, Int>()\n        for (x in A)\n            m[x] = 1 + (m[x] ?: 0)\n        return m.map{ (x, _) -> x }.filter{ m[it]!! == 1 && !m.contains(it - 1) && !m.contains(it + 1) }\n    }\n}\n```\n\n*Javascript*\n```\nlet findLonely = (A, m = new Map()) => {\n    for (let x of A)\n        m.set(x, 1 + (m.get(x) || 0));\n    return [...m].map(([x, _]) => x).filter(x => m.get(x) == 1 && !m.get(x - 1) && !m.get(x + 1));\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def findLonely(self, A: List[int]) -> List[int]:\n        m = Counter(A)\n        return [x for x in m.keys() if m[x] == 1 and x - 1 not in m and x + 1 not in m]\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using Map = unordered_map<int, int>;\n    VI findLonely(VI& A, Map m = {}, VI ans = {}) {\n        for (auto x: A)\n            ++m[x];\n        for (auto [x, _]: m)\n            if (m[x] == 1 && m.find(x - 1) == m.end() && m.find(x + 1) == m.end())\n                ans.push_back(x);\n        return ans;\n    }\n};\n```
[]