Lonely Integer

Sort by

recency

|

459 Discussions

|

  • + 0 comments
    def lonelyinteger(a):
        # Write your code here
        count_array=[0]*100
        
        for i in a:
            count_array[i]+=1
            
        for i in range(0,len(count_array)):
            if count_array[i]==1:
                return i
    
  • + 0 comments

    def lonelyinteger(a): # Write your code here data = Counter(a)

    for key, value in data.items():
        if value == 1:
            return key
    
  • + 0 comments

    Python solution using dictionary instead of Counter method

    def lonelyinteger(a):
        count = {}
        for i in a:
            if i in count:
                count[i] += 1
            else:
                count[i] = 1
        
        out = [ele for ele in count.keys() if count[ele] == 1][0]
        return out
    
  • + 0 comments

    public static int lonelyinteger(List a) { // Write your code here int unique = 0;

        for(int i : a){
            unique = unique ^ i;
        }
        return unique;
    }
    
  • + 0 comments
    from collections import Counter
    def lonelyinteger(a):
        # Write your code here
        data = Counter(a)
        unique_elements = [key for key, value in data.items() if value == 1]
        print(unique_elements[0])
        return unique_elements[0]