Lonely Integer

Sort by

recency

|

928 Discussions

|

  • + 0 comments

    easy way is XOR elements try new Cool method in C#

  • + 0 comments

    js:

    function lonelyinteger(a) { let a1 = a.sort();

    for(let i=0; i<a1.length; i++){
       if(a1[i]!=a1[i+1]&& a1[i]!=a1[i-1])
       {
        return a1[i];
       }
    
    }
    

    }

  • + 0 comments
    def lonelyinteger(a):
        a.sort()
        pil = []
        for number in a:
            if number in pil:
                pil.pop()
            else:
                pil.append(number)
        return pil[-1]
    
  • + 0 comments
    uniqueElement = 0
    for item in a:
        if a.count(item) == 1:
            uniqueElement = item
    
    return uniqueElement
    
  • + 0 comments
    
    
    for i in a:
        if a.count(i)==1:
            return i