题解 | 小红书推荐系统

小红书推荐系统

https://www.nowcoder.com/practice/e5b39c9034a84bf2a5e026b2b9b973d0

Java

哈希+排序

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<String,Integer> hash=new HashMap<>();
        while(in.hasNext()){
            String s=in.next();
            hash.put(s,hash.getOrDefault(s,0)+1);
        }
        List<My> list=new ArrayList<>();
        Set<String> key=hash.keySet();
        for(String k:key){
            Integer v=hash.get(k);
            if(v>=3){
                My my=new My(k,v);
                list.add(my);
            }
        }
        Collections.sort(list,(o1,o2)->{
            if(o1.count!=o2.count){
                return o2.count-o1.count;
            }else{
                return o1.s.compareTo(o2.s);
            }
        });
        for(My my:list){
            System.out.println(my.s);
        }
    }
    
}
class My{
    String s;
    Integer count;
    public My(String s,Integer count){
        this.s=s;
        this.count=count;
    }

    }

全部评论

相关推荐

2025-11-23 15:33
已编辑
门头沟学院 Java
CUTMR:换账号试试重启推荐算法,我换账号之后回复率还不错,约莫有个20%左右的消息回复率,前几页、主动招呼的HR也开始符合我期望薪资,此前的大号从招呼、回复、前几页的岗位薪资在涨幅30%+以上 用着用着聊着聊着就变成-20%,而且我开通会员之后直接0面试
点赞 评论 收藏
分享
allin实习的大白...:我把第二个项目发出来了,如果感兴趣可以去研究研究,欢迎交流。 https://gitee.com/jtyjtyjty333/ind-dist-ai-sec-edge-cloud https://github.com/jtylab/ind-dist-ai-sec-edge-cloud
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务