My Easy Java Solution beats 98.98% !


  • 0
    C

    My Solution beats 98.98%!

    public class Solution {
        public List<Integer> findDuplicates(int[] nums) {
            int[] hash = new int[nums.length];
            List<Integer> list = new ArrayList<Integer>();
            for(int num:nums){
            	hash[num-1]++;
            }
            for(int i=0;i<hash.length;i++){
            	if(hash[i]==2){
            		list.add(i+1);
            	}
            }
            return list;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.