腾讯笔试题记录

function isSubDomain(a, b){
     let aa = a.split('.');
     let bb = b.split('.');

     if (aa.length <= bb.length) {
         console.log('no')
     } else {
         for(let i = bb.length - 1; i >= 0; i--) {
             if (bb[i] != aa[i]) {
                 console.log('no');
                 return;
             }
         }
         console.log('yes')
     }
 }

 function output(str) {
     var arr = str.split('/');
     var h = arr.reduce((prev, cur) => {
         return prev.concat(cur.split(' '))
     }, [])
     arr = [];
     for(let i = 0; i < h.length; i++) {
         if (str[str.indexOf(h[i])+h[i].length] == '/') {
             arr.push(h[i])
         }
     }
     return arr;
 }



 function output(str){
     var res = [];
     var strs = [...str];
     var tmp = '';

     for(let s of strs) {
        if (s == ' ') {
            tmp = '';
        } else if (s == '/') {
            res.push(tmp);
            tmp = '';
        } else {
            tmp += s;
        }
     }

     return res;
 }

 console.log(output('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36'))

function getLeast(k, time, food) {
    for(let i = 0; i < k; i++) {
        let index = 0;
        for(let j = 1; j < time.length; j++) {
            let prev = time[index] * food[index];
            let cur = time[j] * food[j];
            if (cur > prev) {
                index = j;
            }
        }
        if(time[index] == 0) {
            return 0;
        } else {
            time[index] = time[index] - 1;
        }
    }

    let cur = time[0] * food[0];

    for(let i = 1; i < time.length; i++){
        cur = Math.max(cur, time[i] * food[i])
    }
    return cur;
}

console.log(getLeast(5, [4,2,1], [2,3,1]))
console.log(getLeast(8, [4,2,1], [2,3,1]))
全部评论

相关推荐

10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务