小红书测开笔试
测开岗第二题,求大佬看一看我写代码,只通过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<String,Integer> 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);
}
}
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<String,Integer> 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);
}
}
全部评论
佬,其他两道题写咋样
相关推荐
点赞 评论 收藏
分享
2025-11-18 18:24
北京理工大学珠海学院 嵌入式软件工程师
秋招投简历提醒助手:个人经验是,一般面二十场左右就会进入侃侃而谈阶段。我今年七月末的时候开始的第一次面试,都是很多不会,回复很慢。后面慢慢迭代,到九月中的时候基本上面啥说啥,很放松的状态 点赞 评论 收藏
分享
2025-12-25 13:37
门头沟学院 Java
sneak@0729:标准回答:我期望在广州,但我个人其实对地域选择不敏感,更看重公司的前景和个人长期发展。因此base地具体以公司安排为准 点赞 评论 收藏
分享
点赞 评论 收藏
分享