Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Write a program to find the first non-repeating number in an integer array using Java?
To find the first non-repeating number in an array −
- Construct count array to store count of each element in the given array with same length and with initial value 0 for all elements.
- Compare each element in the array with all other elements, except itself.
- If match occurs increment its value in the count array.
- Get the index of the first 0 in the count array and print the element in the input array at this index.
Example
import java.util.Arrays;
public class NonRpeatingArray {
public static void main(String args[]) {
int array[] = {114, 225, 669, 996, 336, 6547, 669, 225, 336, 669, 996, 669, 225 };
System.out.println("");
//Creating the count array
int countArray[] = new int[array.length];
for(int i=0; i
Output
[0, 2, 3, 1, 1, 0, 3, 2, 1, 3, 1, 3, 2]
114
Advertisements
