Hacker Rank Solutions: Lonely Integer

Hacker Rank Solutions: Lonely Integer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def lonelyinteger(array)
  found = []

  array.each do |i|
    if found[i] == nil
      found[i] = 1
    elsif found[i] == 1
      found.delete(i)
    end
  end

  puts found.first
end

a = gets.strip.to_i
b = gets.strip.split(" ").map! {|i| i.to_i}
print lonelyinteger(b)

Comments