Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Q9/pashmeen Q9 solution
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// "static void main" must be defined in a public class.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pashmeen27 , checkout README and CONTRIBUTION files and follow all the guidelines regarding submitting a PR

import java.util.Scanner;
import java.util.HashMap;


public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=s.nextInt();
findDuplicate(arr,n);
Comment on lines +8 to +13
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main Function

}
public static void findDuplicate(int[] arr, int n)
{
HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
for(int i=0;i<n;i++)
{
if(!hm.containsKey(arr[i]))
hm.put(arr[i],1);
else if(hm.containsKey(arr[i]))
{
System.out.println(arr[i]);
return;
}
}
System.out.println("-1");
Comment on lines +17 to +28
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using HasjMap to solve the question

}
}