Same idea .....thanks for view


  • 0
    S
    public class Solution {
        public int distributeCandies(int[] candies) {
            HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
            for(int i=0;i<candies.length;i++){
                map.put(candies[i],candies[i]);
            }
            int result=0;
            int kinds=map.size();
            int half=candies.length/2+candies.length%2;
            return kinds<half?kinds:half;
        }
    }
    

Log in to reply
 

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