小红书测开笔试

测开岗第二题,求大佬看一看我写代码,只通过9%,不知道哪里有问题,求指正#小红书信息集散地#

public class question2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        String[] nums = new String[n];
        int index =0 ;
        while(sc.hasNextLine()){
            if(index == n){
                break;
            }
            nums[index++] = sc.nextLine();
        }
        int result = 0;//背单词的数量
        Map map = new HashMap<>();
        for(int i = 0;i < nums.length;i++){
   
            if(result == 0){
                map.put(nums[i],1);
                result++;
            }
            else{
                if(map.containsKey(nums[i]) &&result == map.get(nums[i])){
                    result++;
                    map.put(nums[i],map.get(nums[i])+1);
                }else{
                    map.put(nums[i],1);
                }
            }
        }
        System.out.println(result);
    }
}
全部评论
佬,其他两道题写咋样
点赞
送花
回复
分享
发布于 2023-08-19 18:58 上海

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务