Solution by vthorat1


  • 0
    V
    class Solution {
        public List<Integer> topKFrequent(int[] nums, int k) {
           List<Integer> list123 = new ArrayList<Integer>();
    
    			for(int i=0;i<nums.length;i++){
                 for(int j=i+1;j<nums.length;j++){
                    if(nums[i]==nums[j]){
                    	
                    	list123.add(nums[i]);
                    }   
                 }
            }
    	       
            Set<Integer> set = new HashSet<Integer>();       
             for(int i=1;i<list123.size();i++){
                  set.add(list123.get(i));
                }//endFori
                
            List<Integer> list = new ArrayList<Integer>(set);
    
            return list;
    
        }
    }
    

Log in to reply
 

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