Question: Using one loop, write a function int uniqueNumber(int[] array) . The input of this function is an int array. This array contains only positive integers.

Using one loop, write a function int uniqueNumber(int[] array). The input of this function is an int array. This array contains only positive integers. Given that every element in this array appeared twice, except for one unique element which appeared only once. Your job is to find and return this unique number.

If every number in this array appeared twice, return -1.

If you can solve this problem using only 1 loop, youll get 5 extra points.

Sample input/output:

Input [3, 3, 2, 4, 4]

Output 2

public class UniqueNumber { public int uniqueNumber (int[]array) { /* Your code goes here*/ } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!