Lonely Integer

Sort by

recency

|

466 Discussions

|

  • + 0 comments

    Without count/counter

    def lonelyinteger(a):
        # Write your code here
        new_arr=[]
        for item in a:
            if item in new_arr:
                new_arr.remove(item)
            else:
                new_arr.append(item)
        return new_arr[0]
    
  • + 0 comments

    Python 3 Solution Readable & Optimised

    def lonelyinteger(a): for i in a: if a.count(i)==1: return i

  • + 0 comments
        public static int lonelyinteger(List<int> a)
        {
            return a.GroupBy(i => i).Single(g => g.Count() == 1).Key;
        }
    
  • + 0 comments

    One liner:

    return [i for i in a if a.count(i) == 1][0]
    
  • + 0 comments

    counters: def lonelyinteger(a): times = Counter(a)

    q =[k for k in times if times[k]==1]
    return q[0]