Skip to content

Create pashmeen Q9 solution#36

Open
pashmeen27 wants to merge 1 commit intoYatharth0045:mainfrom
pashmeen27:patch-1
Open

Create pashmeen Q9 solution#36
pashmeen27 wants to merge 1 commit intoYatharth0045:mainfrom
pashmeen27:patch-1

Conversation

@pashmeen27
Copy link

My solution to Q9 Find Duplicate in array using Java

My solution to Q9 Find Duplicate in array using Java
Comment on lines +8 to +13
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);
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

Comment on lines +17 to +28
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");
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

@ashishdevo28
Copy link
Collaborator

also add run.md with it

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants