Lonely Integer

Sort by

recency

|

450 Discussions

|

  • + 0 comments
    from collections import Counter
    def lonelyinteger(a):
        # Write your code here
        freq = Counter(a)
        for key, value in freq.items():
            if value == 1:
                return key
    
  • + 0 comments

    from collections import Counter

    def lonelyinteger(a): count = Counter(a) for key,val in count.items(): if val == 1: return key

  • + 0 comments

    include

    include // For std::accumulate

    include

    int lonelyinteger(const std::vector& nums) { return std::accumulate(nums.begin(), nums.end(), 0, std::bit_xor()); }

    int main() { std::vector nums = {1, 1, 2, 2, 3}; // Example input std::cout << lonelyinteger(nums) << std::endl; return 0; }

  • + 0 comments

    Kotlin Solution

    fun lonelyinteger(a: Array<Int>): Int {
        return a.groupingBy { it }.eachCount().filterValues { it == 1 }.keys.first()   
    }  
    
  • + 0 comments

    C# solution

    public static int lonelyinteger(List<int> a)
        {
            return a.Find(x => a.Count(j => x == j) == 1);
        }