Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA) Problem description: You will need to write a function int uniqueNumber(int[] array). The input of this function is an int array. This array contains

(JAVA) Problem description: You will need to 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 Input [1, 2, 3, 1, 4, 2, 3] Output 4 Input [1] Output 1 Explanation: The only element in this array is unique. Input [1, 1, 2, 2, 3, 3] Output -1 Explanation Every number in this array appeared twice. Hence, the output is -1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions