推荐结果打散 (快手面试题目) 用两个队列

简介: 推荐结果打散 (快手面试题目) 用两个队列

image.png


public List<String> getRecommendenResult(List<String> picAndVideo,int maxInterval){
    List<String> result=new ArrayList<>();
    if(picAndVideo==null || picAndVideo.size()==0){
        return result;
    }
    Queue<String> videoQueue=new LinkedList<>();
    Queue<String> picQueue=new LinkedList<>();
    boolean firstPic=false;
    int index=0;
    int pciAndVideoSize=picAndVideo.size();
    while(!firstPic&&index<picAndVideo.size()){
        if(isVideo(picAndVideo.get(index))){
            result.add(index,pciAndVideo.get(index));
        }else{
            first=true;
        }
    }
    while(index<picAndVideoSize){
        if(isVideo(picAndVideo.get(index))){
            videoQueue.add(index,picAndVideo.get(index));
        }else{
            picQueue.add(index,picAndVideo.get(index));
        }
    }
    int currentSize=result.size();
    while(!videoQueue.isEmpty()&&!picQueue.isEmpty()){
        if(currentSize>=maxInterval){
            result.add(picQueue.poll());
            currentSize=0;
        }else{
            result.add(videoQueue.poll());
            currentSize++;
        }
    }
    while(!videoQueue.isEmpty()){
        result.add(videoQueue.poll());
    }
    if(currentSize>=maxInteral&&!picQueue.isEmpty()){
        result.add(pic.poll());
    }
    return result;
}
public boolean isVideo(String clip){
   if(clip.indexOf("v")!=-1){
       return true;
   }
   return false;
}
目录
相关文章
|
4月前
|
存储 前端开发 JavaScript
【面试题】Promise只会概念远远不够,还需这17道题目巩固!
【面试题】Promise只会概念远远不够,还需这17道题目巩固!
|
7月前
【栈和队列面试题】用栈实现队列(动图解析更清晰)
【栈和队列面试题】用栈实现队列(动图解析更清晰)
|
5月前
|
算法 容器
【算法训练营】队列合集(2) 2073. 买票需要的时间 || 面试题 03.04. 化栈为队 ||
【算法训练营】队列合集(2) 2073. 买票需要的时间 || 面试题 03.04. 化栈为队 ||
63 0
|
7月前
|
存储 网络协议 安全
嵌入式面试题目汇总之经典
嵌入式面试题目汇总之经典
81 1
|
2月前
|
JavaScript 前端开发 API
vue面试题目汇总
vue面试题目汇总
40 4
|
2月前
|
算法 Linux 调度
嵌入式linux面试题目总结
嵌入式linux面试题目总结
49 0
|
3月前
|
安全 Java 编译器
Go语言面试宝典:50道必会题目与精解
本文提供了50道覆盖Go语言核心概念、并发编程、内存管理、包管理、错误处理和测试等方面的面试题及其详细答案,旨在帮助开发者全面准备Go语言技术面试。
|
3月前
|
存储 前端开发 搜索推荐
【数据结构入门精讲 | 第六篇】队列知识点及考研408、企业面试练习
【数据结构入门精讲 | 第六篇】队列知识点及考研408、企业面试练习
78 0
|
3月前
|
Linux
面试题12: 基本Linux 命令题目
面试题12: 基本Linux 命令题目
|
4月前
|
存储 JavaScript 安全
Vue基础面试题题目一
Vue基础面试题题目一
31 0