Given an array of integers, where all elements but one occur twice, find the unique element.
The unique element is .
Complete the lonelyinteger function in the editor below.
lonelyinteger has the following parameter(s):
- int a[n]: an array of integers
- int: the element that occurs only once
The first line contains a single integer, , the number of integers in the array.
The second line contains space-separated integers that describe the values in .
HackerRank Lonely Integer SOLUTIONS:
You are given an array of integers and every integer except one occurs more than once. The integer that doesn’t have a repeating value inside the array is considered unique. The goal of the function is to output that unique number.
let a = [1,1,2,2,6];
Looking at our array input above, values
2 have repeating values but
6 is the only number that doesn’t. The function will return
6 because it is a unique number.
Let’s turn this problem into code.