Lonely Integer

Sort by

recency

|

233 Discussions

|

  • + 0 comments

    Simple Python 3 solution

    Here We are using XOR operator (^) so as to identify unique element in the array. Give a like as support and learn

    def lonelyinteger(a):

    unique=0
    for i in a:
        unique ^=i
    return(unique)
    
  • + 0 comments

    yo guys this is simpler and more effecient.....

    from collections import Counter as c

    at #write your code replace it with res=c(a) for i in a: if res[i]==1: return i

  • + 0 comments

    The solution to the problem is by summing xor values;

    return std::accumulate(a.begin(), a.end(), 0, std::bit_xor<int>{});
    
  • + 0 comments

    ** int lonelyinteger(vector a) { map freq; for(int i=0;i for(auto i:freq) { if(i.second == 1) { return (i.first); }

    }
    return -1;
    

    } **

  • + 0 comments

    Save time and space I believe

    int result = 0; Map count = new HashMap<>();

    for(int num : a) { if(count.containsKey(num)) { count.remove(num); } else { count.put(num, 0); } } for(Map.Entry entry : count.entrySet()) { result = entry.getKey(); }

        return result;