LEETCODE Find the duplicate number

 class Solution {

    public int findDuplicate(int[] nums) {

        HashSet<Integer> aa=new HashSet<Integer>();

        int m=0;

        for(int i=0;i<nums.length;i++){

            if(aa.contains(nums[i])){

                m=nums[i];

                System.out.println(nums[i]);

            }

            else

                aa.add(nums[i]);

        }

        return m;

    }

    

    

}

Comments

Popular posts from this blog

Java Date And Time HackerRank

Recursive Sequence Geeks For Geeks Problem Of The Day 12-02-2024

Minimum Indices HackerEarth